mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-08 20:58:05 +00:00

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.
83 lines
1.8 KiB
Rust
83 lines
1.8 KiB
Rust
use {
|
|
ruff_text_size::{TextRange, TextSize},
|
|
serde_test::{Token, assert_de_tokens_error, assert_tokens},
|
|
std::ops,
|
|
};
|
|
|
|
fn size(x: u32) -> TextSize {
|
|
TextSize::from(x)
|
|
}
|
|
|
|
fn range(x: ops::Range<u32>) -> TextRange {
|
|
TextRange::new(x.start.into(), x.end.into())
|
|
}
|
|
|
|
#[test]
|
|
fn size_serialization() {
|
|
assert_tokens(&size(00), &[Token::U32(00)]);
|
|
assert_tokens(&size(10), &[Token::U32(10)]);
|
|
assert_tokens(&size(20), &[Token::U32(20)]);
|
|
assert_tokens(&size(30), &[Token::U32(30)]);
|
|
}
|
|
|
|
#[test]
|
|
fn range_serialization() {
|
|
assert_tokens(
|
|
&range(00..10),
|
|
&[
|
|
Token::Tuple { len: 2 },
|
|
Token::U32(00),
|
|
Token::U32(10),
|
|
Token::TupleEnd,
|
|
],
|
|
);
|
|
assert_tokens(
|
|
&range(10..20),
|
|
&[
|
|
Token::Tuple { len: 2 },
|
|
Token::U32(10),
|
|
Token::U32(20),
|
|
Token::TupleEnd,
|
|
],
|
|
);
|
|
assert_tokens(
|
|
&range(20..30),
|
|
&[
|
|
Token::Tuple { len: 2 },
|
|
Token::U32(20),
|
|
Token::U32(30),
|
|
Token::TupleEnd,
|
|
],
|
|
);
|
|
assert_tokens(
|
|
&range(30..40),
|
|
&[
|
|
Token::Tuple { len: 2 },
|
|
Token::U32(30),
|
|
Token::U32(40),
|
|
Token::TupleEnd,
|
|
],
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_range_deserialization() {
|
|
assert_tokens::<TextRange>(
|
|
&range(62..92),
|
|
&[
|
|
Token::Tuple { len: 2 },
|
|
Token::U32(62),
|
|
Token::U32(92),
|
|
Token::TupleEnd,
|
|
],
|
|
);
|
|
assert_de_tokens_error::<TextRange>(
|
|
&[
|
|
Token::Tuple { len: 2 },
|
|
Token::U32(92),
|
|
Token::U32(62),
|
|
Token::TupleEnd,
|
|
],
|
|
"invalid range: 92..62",
|
|
);
|
|
}
|