From 569c94b71b29e4a49aaf95ae5da9a56c19714f1e Mon Sep 17 00:00:00 2001 From: Douglas Creager Date: Mon, 19 May 2025 11:40:58 -0400 Subject: [PATCH] Add rustfmt.toml file (#18197) 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 (https://github.com/rust-lang/rust.vim/issues/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. --- Cargo.toml | 1 + crates/ruff_text_size/Cargo.toml | 9 +++++++-- crates/ruff_text_size/src/schemars_impls.rs | 2 +- crates/ruff_text_size/src/serde_impls.rs | 2 +- crates/ruff_text_size/tests/serde.rs | 2 +- rustfmt.toml | 2 ++ 6 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 rustfmt.toml diff --git a/Cargo.toml b/Cargo.toml index 6f9c967b78..7461248654 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = ["crates/*"] resolver = "2" [workspace.package] +# Please update rustfmt.toml when bumping the Rust edition edition = "2024" rust-version = "1.85" homepage = "https://docs.astral.sh/ruff" diff --git a/crates/ruff_text_size/Cargo.toml b/crates/ruff_text_size/Cargo.toml index d51954503b..19de486464 100644 --- a/crates/ruff_text_size/Cargo.toml +++ b/crates/ruff_text_size/Cargo.toml @@ -2,8 +2,13 @@ name = "ruff_text_size" version = "0.0.0" publish = false -edition = "2021" -rust-version = "1.67.1" +authors = { workspace = true } +edition = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +documentation = { workspace = true } +repository = { workspace = true } +license = { workspace = true } [dependencies] serde = { workspace = true, optional = true } diff --git a/crates/ruff_text_size/src/schemars_impls.rs b/crates/ruff_text_size/src/schemars_impls.rs index 0a594d21c0..4bc9ba2e01 100644 --- a/crates/ruff_text_size/src/schemars_impls.rs +++ b/crates/ruff_text_size/src/schemars_impls.rs @@ -6,7 +6,7 @@ //! bindings to the Workspace API use crate::{TextRange, TextSize}; -use schemars::{r#gen::SchemaGenerator, schema::Schema, JsonSchema}; +use schemars::{JsonSchema, r#gen::SchemaGenerator, schema::Schema}; impl JsonSchema for TextSize { fn schema_name() -> String { diff --git a/crates/ruff_text_size/src/serde_impls.rs b/crates/ruff_text_size/src/serde_impls.rs index 42e0017ec0..7558e9769e 100644 --- a/crates/ruff_text_size/src/serde_impls.rs +++ b/crates/ruff_text_size/src/serde_impls.rs @@ -1,6 +1,6 @@ use { crate::{TextRange, TextSize}, - serde::{de, Deserialize, Deserializer, Serialize, Serializer}, + serde::{Deserialize, Deserializer, Serialize, Serializer, de}, }; impl Serialize for TextSize { diff --git a/crates/ruff_text_size/tests/serde.rs b/crates/ruff_text_size/tests/serde.rs index 0d8f9d4a6a..606b416833 100644 --- a/crates/ruff_text_size/tests/serde.rs +++ b/crates/ruff_text_size/tests/serde.rs @@ -1,6 +1,6 @@ use { ruff_text_size::{TextRange, TextSize}, - serde_test::{assert_de_tokens_error, assert_tokens, Token}, + serde_test::{Token, assert_de_tokens_error, assert_tokens}, std::ops, }; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000000..f3e454b618 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +edition = "2024" +style_edition = "2024"