Repository navigation
Description
The simplest test case I've been able to come up with so far is this:
mod a {
mod b {
#[doc = "test"]fn foo() -> () { }
}
}with config
normalize_doc_attributes=true
max_width=10This example gets reformatted to the following, although it does report an error because the line exceeds the maximum width.
mod a {
mod b {
///testfn foo() -> (){
}
}
}I'm still not sure exactly what triggers this bug, but have found a lot of variants for this example which don't trigger it. Here are a few that might be significant:
#[doc = "test"]fn foo() -> () { }mod a {
mod b {
#[doc = "test"]fn foo() { }
}
}mod a {
mod b {
#[doc = "test"]
fn foo() -> () { }
}
}mod a {
mod b {
/// test
fn foo() -> () { }
}
}In these examples, removing max_width=10 fixes the issue, but I encountered this originally in a situation where rustfmt was inexplicably being run on autogenerated files in the target directory that were part of the wayland-protocol crate. I haven't figured out what was causing rustfmt to process those files in the first place, but in that case I did have max_width=80 instead.
I have no clue what's happening or how to fix it at this point, but I'm pretty sure it has to do with formatting lines that are longer than max_width combined with some unknown other requirement. I'll try to look into this more soon and see if I can figure out how to fix it.
Activity
elinorbgr commentedon Feb 3, 2020
An other example that triggers this:
This original (generated) code:
gets formatted as
when run using these rustfmt options:
As seen, this comments part of the code.
burrbull commentedon Apr 14, 2021
Looks like this issue not in "normalize_doc_attributes" but in "max_width"
Because using
max_width=10only producesinstead of to add newline
I think it works incorrect with any attribute:
with
max_width=7producesBut with
max_width=6:burrbull commentedon Apr 27, 2021
Without attributes
Input:
Output with
with max_width=10:Output with
with max_width=7:Output with
with max_width=6and less:6 can be calculated as 4 (result indent of first line) + 2
ytmimi commentedon Jul 26, 2022
confirming this is still reproducible with
rustfmt 1.5.1-nightly (a451a39d 2022-07-25)ahl commentedon Apr 23, 2024
I hit this today as well:
input:
output: