Skip to content

Commit 569c94b

Browse files
authored
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 (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.
1 parent 59d80af commit 569c94b

File tree

6 files changed

+13
-5
lines changed

6 files changed

+13
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6+
# Please update rustfmt.toml when bumping the Rust edition
67
edition = "2024"
78
rust-version = "1.85"
89
homepage = "https://docs.astral.sh/ruff"

crates/ruff_text_size/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
name = "ruff_text_size"
33
version = "0.0.0"
44
publish = false
5-
edition = "2021"
6-
rust-version = "1.67.1"
5+
authors = { workspace = true }
6+
edition = { workspace = true }
7+
rust-version = { workspace = true }
8+
homepage = { workspace = true }
9+
documentation = { workspace = true }
10+
repository = { workspace = true }
11+
license = { workspace = true }
712

813
[dependencies]
914
serde = { workspace = true, optional = true }

crates/ruff_text_size/src/schemars_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! bindings to the Workspace API
77
88
use crate::{TextRange, TextSize};
9-
use schemars::{r#gen::SchemaGenerator, schema::Schema, JsonSchema};
9+
use schemars::{JsonSchema, r#gen::SchemaGenerator, schema::Schema};
1010

1111
impl JsonSchema for TextSize {
1212
fn schema_name() -> String {

crates/ruff_text_size/src/serde_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{TextRange, TextSize},
3-
serde::{de, Deserialize, Deserializer, Serialize, Serializer},
3+
serde::{Deserialize, Deserializer, Serialize, Serializer, de},
44
};
55

66
impl Serialize for TextSize {

crates/ruff_text_size/tests/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
ruff_text_size::{TextRange, TextSize},
3-
serde_test::{assert_de_tokens_error, assert_tokens, Token},
3+
serde_test::{Token, assert_de_tokens_error, assert_tokens},
44
std::ops,
55
};
66

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
edition = "2024"
2+
style_edition = "2024"

0 commit comments

Comments
 (0)