Trailing whitespace remains when passing `--edition 2024`
❯ rustfmt --version
rustfmt 1.8.0-stable (4d91de4e48 2025-02-17)
Consider the following file foo.rs:
fn f() {} // This has trailing whitespace
The trailing whitespace remains when calling rustfmt --edition 2024 foo.rs but rustfmt foo.rs removes it.
Thanks! confirming that I can reproduce this behavior with rustfmt 1.8.0-nightly (fd0ea742f8 2025-04-12) (built from source).
Running cargo run --bin rustfmt -- --style-edition={2015|2018|2021} all remove the trailing whitespace, while running rustfmt with --style-edition=2024 keeps the trailing whitespace.
error[internal]: left behind trailing whitespace
--> <stdin>:1:1:42
|
1 | fn f() {} // This has trailing whitespace
| ^^
|
= note: set `error_on_unformatted = false` to suppress the warning against comments or string literals
I have the same issue, except that running
cargo fmt -- --style-edition=2021
does not remove the whitespace and rustfmt still returns errors:
error[internal]: left behind trailing whitespace
--> /Users/james/src/blachlylab/wodehouse/src/lib/routes/layout.rs:129:129:81
|
129 | (layout.visibility == crate::models::userdef::Visibility::AccountWide &&
| ^
Version: rustfmt 1.8.0-nightly (f3db63916e 2025-06-17)
Code in question is:
// Check permissions based on visibility
let can_access =
// User owns the layout
layout.user_id == uid ||
// Layout is public
layout.visibility == crate::models::userdef::Visibility::Public ||
// Layout is account-wide and user is in the same account
(layout.visibility == crate::models::userdef::Visibility::AccountWide &&
user.account_id.is_some() &&
conn.run(move |c| {
use diesel::prelude::*;
use crate::schema::users::dsl::*;
users
...
and the trailing whitespace is after the boolean operators || and &&
@jblachly you're issue is off topic. It's a duplicate of #3591 and other linked issues. rustfmt won't format binary expressions if they contain comments in the because they would otherwise be deleted.