rustfmt
rustfmt copied to clipboard
Non-idempotent repeatedly growing indentation in doc attribute containing multi-line concat
Minimized from https://github.com/rust-lang/rust/blob/1.74.0/library/core/src/num/nonzero.rs#L341-L342.
macro_rules! repro {
() => {
#[doc = concat!("let var = ",
"false;")]
fn f() {}
};
}
As of current master, rustfmt applies the following diff. This is from cargo run --bin rustfmt -- /path/to/repro.rs
.
- "false;")]
+ "false;")]
If you run rustfmt again, it keeps going for 16 levels of indentation before reaching an idempotent state.
- "false;")]
+ "false;")]
- "false;")]
+ "false;")]
- "false;")]
+ "false;")]
- "false;")]
+ "false;")]
- "false;")]
+ "false;")]
- "false;")]
+ "false;")]
- "false;")]
+ "false;")]
- "false;")]
+ "false;")]
@rustbot claim
Had this issue happen to me as well, with the following (on rustfmt 1.7.1-nightly (fda509e 2024-06-25)
):
macro_rules! my_macro {
() => {
// Breaks
#[doc(concat!(
"Multi\
Line"
))]
pub struct Struct;
// Incorrect but not broken
#[doc(
"Multi\
Line",
)]
pub struct Struct;
};
}
// Normal
#[doc(concat!(
"Multi\
Line"
))]
pub struct Struct;
https://github.com/user-attachments/assets/c84fdf8f-bc49-4fc0-8aba-ebba8d0f8038
I noticed that there seems to be a difference when I don't use the concat!()
macro call. Also, I'm using a single string, just split over multiple lines.
Possible related to #6161?