Skip to content

Conversation

@dcreager
Copy link
Member

My editor runs rustfmt on save to format Rust code, not cargo fmt.

With our recent bump to the Rust 2024 edition, the formatting that rustfmt/cargo fmt applies changed. Unfortunately, rustfmt and cargo fmt have different behaviors for determining which edition to use when formatting: cargo fmt looks for the Rust edition in Cargo.toml, whereas rustfmt looks for it in rustfmt.toml. As a result, whenever I save, I have to remember to manually run cargo fmt before committing/pushing.

There is an open issue asking for rustfmt to also look at Cargo.toml when 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.toml file with our current Rust edition so that both invocation have the same behavior. I don't love that this duplicates information in Cargo.toml, but I've added a reminder comment there to hopefully ensure that we bump the edition in both places three years from now.

@dcreager dcreager added the internal An internal refactor or improvement label May 19, 2025
@dcreager
Copy link
Member Author

The ruff_text_size crate was hard-coding a Rust edition instead of inheriting it from the workspace. Updated that crate to be consistent with the other internal crates

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@dcreager dcreager merged commit 569c94b into main May 19, 2025
34 checks passed
@dcreager dcreager deleted the dcreager/rustfmt branch May 19, 2025 15:41
dcreager added a commit that referenced this pull request May 19, 2025
* main:
  [ty] Infer function call typevars in both directions (#18155)
  Add rustfmt.toml file (#18197)
  [ty] Update mypy primer (#18196)
  [ty] Mark generated files as such in .gitattributes (#18195)
  [ty] Support `typing.TypeAliasType` (#18156)
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

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants