Skip to content

Commit fb36c14

Browse files
committed
issue(5801): do not change shape before formatting enum comments
do not change shape as not formatting doc comments correctly sub_width has no impact on tests, also removing add version gate and review comments remove unused variable test unexpected wrapping in version one test version 2 does not wrap remove unneeded config remove unneeded config params
1 parent 75e3172 commit fb36c14

6 files changed

+82
-3
lines changed

src/items.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,16 @@ impl<'a> FmtVisitor<'a> {
656656
}
657657

658658
let context = self.get_context();
659-
// 1 = ','
660-
let shape = self.shape().sub_width(1)?;
661-
let attrs_str = field.attrs.rewrite(&context, shape)?;
659+
let shape = self.shape();
660+
let attrs_str = if context.config.version() == Version::Two {
661+
field.attrs.rewrite(&context, shape)?
662+
} else {
663+
// Version::One formatting that was off by 1. See issue #5801
664+
field.attrs.rewrite(&context, shape.sub_width(1)?)?
665+
};
666+
// sub_width(1) to take the trailing comma into account
667+
let shape = shape.sub_width(1)?;
668+
662669
let lo = field
663670
.attrs
664671
.last()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-max_width: 120
2+
// rustfmt-version: One
3+
// rustfmt-attr_fn_like_width: 120
4+
5+
pub enum Severity {
6+
#[something(AAAAAAAAAAAAA, BBBBBBBBBBBBBB, CCCCCCCCCCCCCCCC, DDDDDDDDDDDDD, EEEEEEEEEEEE, FFFFFFFFFFF, GGGGGGGGGGG)]
7+
AttrsWillWrap,
8+
#[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)]
9+
AttsWontWrap,
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-max_width: 120
2+
// rustfmt-version: Two
3+
// rustfmt-attr_fn_like_width: 120
4+
5+
pub enum Severity {
6+
#[something(AAAAAAAAAAAAA, BBBBBBBBBBBBBB, CCCCCCCCCCCCCCCC, DDDDDDDDDDDDD, EEEEEEEEEEEE, FFFFFFFFFFF, GGGGGGGGGGG)]
7+
AttrsWillWrap,
8+
#[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)]
9+
AttsWontWrap,
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// rustfmt-max_width: 120
2+
// rustfmt-version: One
3+
// rustfmt-attr_fn_like_width: 120
4+
5+
pub enum Severity {
6+
#[something(
7+
AAAAAAAAAAAAA,
8+
BBBBBBBBBBBBBB,
9+
CCCCCCCCCCCCCCCC,
10+
DDDDDDDDDDDDD,
11+
EEEEEEEEEEEE,
12+
FFFFFFFFFFF,
13+
GGGGGGGGGGG
14+
)]
15+
AttrsWillWrap,
16+
#[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)]
17+
AttsWontWrap,
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// rustfmt-comment_width: 120
2+
// rustfmt-wrap_comments: true
3+
// rustfmt-max_width: 120
4+
// rustfmt-version: Two
5+
6+
/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine
7+
fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String {
8+
unimplemented!()
9+
}
10+
11+
pub enum Severity {
12+
/// But here, this comment is 120 columns wide and the formatter wants to split it up onto two separate lines still.
13+
Error,
14+
/// This comment is 119 columns wide and works perfectly. Lorem ipsum. lorem ipsum. lorem ipsum. lorem ipsum lorem.
15+
Warning,
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// rustfmt-comment_width: 120
2+
// rustfmt-wrap_comments: true
3+
// rustfmt-max_width: 120
4+
// rustfmt-version: One
5+
6+
/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine
7+
fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String {
8+
unimplemented!()
9+
}
10+
11+
pub enum Severity {
12+
/// In version one, the below line got wrapped prematurely as we subtracted 1 to account for `,`. See issue #5801.
13+
/// But here, this comment is 120 columns wide and the formatter wants to split it up onto two separate lines
14+
/// still.
15+
Error,
16+
/// This comment is 119 columns wide and works perfectly. Lorem ipsum. lorem ipsum. lorem ipsum. lorem ipsum lorem.
17+
Warning,
18+
}

0 commit comments

Comments
 (0)