-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply rustfmt formatting (partial) #926
Conversation
(Several array reformattings were rejected.)
This does not include all cases of rejected reformatting; only ones where rustfmt is not expected to do well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since no one else has reviewed this and I'm not "allowed" to self-review (GH restriction), I'm just going to make some comments and merge anyway:
- I'm pretty sure there are no semantic changes here (other than to rustfmt config)
- Syntactic changes are mixed and use a few more lines overall, but for the most part are an improvement
- Aligning with Rustfmt formatting is (broadly speaking) sensible
- It's a shame this PR doesn't get all the way there
println!("v: {}", v[i]); | ||
e | ||
}) | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this decreases readability, but I guess it's good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess you're right. Feel free to post rustfmt config changes / a skip annotation if you prefer.
I'd really like to get the point where we can just run cargo fmt
on the project so would prefer not to just revert stuff like this — but it may not be until Rustfmt 2.0 that we get there (and even then, we'll have to make further compromises).
I think there are some minor readability regressions, where the code is spread over too many lines, but I think this is a small annoyance outweighed by the advantages of automatic formatting. |
Glad we agree on that then. Try running |
Ok, here are my observations with rustfmt 1.4.11-nightly (1838235 2019-12-03): I think the following changes will hopefully improve in a later rustfmt version:
I think some changes have to be manually disabled by annotating the source code:
In my opinion, the remaining changes suggested by rustfmt are acceptable (even if not great). This actually looks better: diff --git a/src/distributions/binomial.rs b/src/distributions/binomial.rs
index c096e4a862..53363c6e99 100644
--- a/src/distributions/binomial.rs
+++ b/src/distributions/binomial.rs
@@ -229,7 +229,7 @@ impl Distribution<u64> for Binomial {
}
if alpha
- > x_m * (f1 / x1).ln()
+ > x_m * (f1 / x1).ln()
+ (n - (m as f64) + 0.5) * (z / w).ln() |
Generally I agree, though there are a couple of cases where current formatting deliberately breaks over multiple lines.
I think the only way this type of thing can be done correctly is to weight styles by similarity to previous/next lines as well as a soft length limit.
There is some interest in vertical alignment; it's already implemented for a couple of things (e.g. enum values).
It appears I got this wrong (but right in the |
Rustfmt is now widely used and mostly gives a good result. This PR:
However, some reformatting was rejected without a skip command:
index..=index + 1
rustfmt::skip
, but it can't be applied toif
expressions or inside blocks)I have created several new issues on the rustfmt repository; ideally the remaining formatting issues can be resolved via
rustfmt
improvement.For now, we still can't just run
cargo fmt
on the project.