-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add rustfmt.toml file #18197
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
Merged
Merged
Add rustfmt.toml file #18197
+13
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
Author
|
The |
Contributor
|
MichaReiser
approved these changes
May 19, 2025
dcreager
added a commit
that referenced
this pull request
May 19, 2025
BurntSushi
added a commit
to astral-sh/uv
that referenced
this pull request
Jun 16, 2025
We've gotten away without this file for a while. In particular, we explicitly use its default settings. However, this is occasionally problematic in certain contexts where `rustfmt` is invoked directly. Or in contexts where the Rust Edition is otherwise not specified. At least, this happens when using the Rust vim plugin. When an edition isn't explicitly specified, it defaults back to the 2015 edition. I think that there aren't a lot of rustfmt changes, and so we've been able to get away with this for a while. But it looks like something in the 2024 edition changes how imports are ordered. So to make it explicit that we want to use the 2024 edition of rustfmt, we opt into it. This is analogous to a change made to the Ruff repository somewhat recently: astral-sh/ruff#18197
BurntSushi
added a commit
to astral-sh/uv
that referenced
this pull request
Jun 16, 2025
We've gotten away without this file for a while. In particular, we explicitly use its default settings. However, this is occasionally problematic in certain contexts where `rustfmt` is invoked directly. Or in contexts where the Rust Edition is otherwise not specified. At least, this happens when using the Rust vim plugin. When an edition isn't explicitly specified, it defaults back to the 2015 edition. I think that there aren't a lot of rustfmt changes, and so we've been able to get away with this for a while. But it looks like something in the 2024 edition changes how imports are ordered. So to make it explicit that we want to use the 2024 edition of rustfmt, we opt into it. This is analogous to a change made to the Ruff repository somewhat recently: astral-sh/ruff#18197
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My editor runs
rustfmton save to format Rust code, notcargo fmt.With our recent bump to the Rust 2024 edition, the formatting that
rustfmt/cargo fmtapplies changed. Unfortunately,rustfmtandcargo fmthave different behaviors for determining which edition to use when formatting:cargo fmtlooks for the Rust edition inCargo.toml, whereasrustfmtlooks for it inrustfmt.toml. As a result, whenever I save, I have to remember to manually runcargo fmtbefore committing/pushing.There is an open issue asking for
rustfmtto also look atCargo.tomlwhen it's present (rust-lang/rust.vim#368), but it seems like they "closed" that issue just by bumping the default edition (six years ago, from 2015 to 2018).In the meantime, this PR adds a
rustfmt.tomlfile with our current Rust edition so that both invocation have the same behavior. I don't love that this duplicates information inCargo.toml, but I've added a reminder comment there to hopefully ensure that we bump the edition in both places three years from now.