Skip to content

Commit ad652ca

Browse files
committed
add version gate and review comments
1 parent a4a18d3 commit ad652ca

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/items.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ impl<'a> FmtVisitor<'a> {
630630
items = itemize_list_with(0);
631631
}
632632

633-
let shape = self.shape();
633+
let shape = self.shape().sub_width(2)?;
634634
let fmt = ListFormatting::new(shape, self.config)
635635
.trailing_separator(self.config.trailing_comma())
636636
.preserve_newline(true);
@@ -658,6 +658,14 @@ impl<'a> FmtVisitor<'a> {
658658
let context = self.get_context();
659659
let shape = self.shape();
660660
let attrs_str = field.attrs.rewrite(&context, shape)?;
661+
let attrs_str = if context.config.version() == Version::Two {
662+
field.attrs.rewrite(&context, shape)?
663+
} else {
664+
// Version::One formatting that was off by 1. See issue #5801
665+
field.attrs.rewrite(&context, shape.sub_width(1)?)?
666+
};
667+
// sub_width(1) to take the trailing comma into account
668+
let shape = shape.sub_width(1)?;
661669
let lo = field
662670
.attrs
663671
.last()

tests/source/configs/comment_width/5801.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/target/configs/comment_width/5801.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// rustfmt-comment_width: 120
22
// rustfmt-wrap_comments: true
3-
// rustfmt-unstable_features: true
43
// rustfmt-max_width: 120
4+
// rustfmt-version: Two
55

66
/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine
77
fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String {

0 commit comments

Comments
 (0)