-
Notifications
You must be signed in to change notification settings - Fork 76
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
better understand rustfmt stability #77
Comments
I can get onboard with option 3. As much as there are some formatting choices I don't love, the vast majority of my concern is for stable formatting and simplicity so the actual output matters a little less to me. If you can't stomach 3, then agreed that 2 looks good. I think that if we go w/ 2 we should change .vscode/settings.json to {
"rust-analyzer.rustfmt.overrideCommand": [
"rustup",
"run",
"nightly",
"rustfmt"
]
} Is that right? |
Resolved with #242. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See #76 for background. I wanted to see if there was a better approach here. I found that rustfmt intends that your code should not be reformatted if you stick to stable options. From my testing, this appears to be true both with stable options and with the unstable options that we're using in Dropshot. (We previously thought that we were seeing a bunch of churn. I now suspect that churn was a result of accidentally switching between nightly and stable versions of otherwise equivalent
rustfmt
releases. Details below.)Given that, I see three options here:
rustfmt
and we tell them which specific release to use. Developers are expected to configure this correctly for themselves, whether that's vim, VScode (settings for which are in this repo), or muscle memory (cargo +nightly-2020-07-26 fmt
rather thancargo fmt
).require_version
fromrustfmt.toml
. We document that developers must usenightly
, and that we expect any nightly is likely to work. (If we run into cases where a specific nightly starts formatting the code differently, we'll see that in the pre-integration check.) In this case, we're using nightly only for its policy that unstable options are supported, not because we need a bleeding-edge version of the software. Like option (1), developers still have to configure things locally. On the plus side, we don't have to keep bumping the specificrequire_version
, CI config, or README instructions. Right now, there's basically no reason to ever bump these unless that build stops becoming available or we adopt a newer rustfmt that actually changes the way code is formatted. But people might be confused about why our instructions reference an ancient 2020-07 nightly build or suggest that we update it. Instead, the CI can use the known-good version until we need to update it, and everybody else can just see and remember "nightly" rather than "nightly-2020-07-26". (This might be a pretty big advantage for people that use "nightly" for other purposes -- like other projects that require "nightly" -- since they can use that toolchain for Dropshot, too.)require_version
. Keep us on stable rustfmt. This is smoothest for everybody -- you only need one toolchain, you don't need any custom local config, and there's nothing to forget about.Option 3 sounds great, but some of the defaults really do seem unfortunate. Here's the result of reformatting today's Dropshot with the default options:
7d12647
By my spot check: most of the changes appear due to
struct_lit_single_line
, and they mostly look a lot less readable to me. Here's a typical example:7d12647#diff-1feac7e55ea61939c504aaa3cfc07e35ca99d8eb3b38cb154a0866302832a73fR350
Maybe I'm overthinking it, though. That one sucks because Projects are eventually going to have lots of fields, but when they do, they won't fit on one line anyway. @ahl What do you think?
If we don't go with (3), I'm tempted by (2) so that people don't forever need to remember 2020-07-26.
Methodology
Feel free to skip this.
I wanted to answer the question: if we just used stable rustfmt, how often would we wind up reformatting our code?
My plan was to identify the
rustfmt
versions that shipped with stable Rust releases in 2020, reformat Dropshot with the first one, then create a sequence of commits showing the diffs from each stable version's rustfmt to the next. I created two branches to show this:require_version
), and then does what I said: one commit for each subsequent rustfmt version (that shipped with a stable Rust version). Each commit shows the changes between two rustfmt versions.require_version
option so that we can test with different versions. Then it proceeds as in the other case. This was trickier than above because in order to support the unstable options, we have to be using a nightly version. I didn't go track down which nightly toolchain corresponded with each stable release's rustfmt. Instead, I grabbed 13 nightly builds, spaced about a month apart, and tested those.As promised, the code never changed in the stable branch. But to our surprise, the code also didn't change in the unstable branch. This contradicted our previous experience! Looking through logs, I now suspect that when we thought things had changed between versions, they actually changed because
rustfmt
was run under "stable", not "nightly", and it ignored several key options.See above for a summary of our choices, given this information.
For posterity, here's the (awful, unpolished) script that I used:
The text was updated successfully, but these errors were encountered: