Skip to content

Commit a1e4f8e

Browse files
committed
Fix formatting of comments in empty structs
1 parent 5056f4c commit a1e4f8e

File tree

7 files changed

+28
-37
lines changed

7 files changed

+28
-37
lines changed

src/items.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,10 @@ fn format_empty_struct_or_tuple(
13741374
result.push_str(&offset.to_string_with_newline(context.config))
13751375
}
13761376
result.push_str(opener);
1377-
match rewrite_missing_comment(span, Shape::indented(offset, context.config), context) {
1377+
1378+
// indented shape for proper indenting of multi-line comments
1379+
let shape = Shape::indented(offset.block_indent(context.config), context.config);
1380+
match rewrite_missing_comment(span, shape, context) {
13781381
Some(ref s) if s.is_empty() => (),
13791382
Some(ref s) => {
13801383
if !is_single_line(s) || first_line_contains_single_line_comment(s) {

tests/source/comments-in-lists/wrap-comments-not-normalized.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ pub enum E {
1313
}
1414

1515
pub enum E2 {
16-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
17-
// Expand as needed, numbers should be ascending according to the stage
18-
// through the inclusion pipeline, or according to the descriptions
16+
// Expand as needed, numbers should be ascending according to the stage
17+
// through the inclusion pipeline, or according to the descriptions
1918
}
2019

2120
pub enum E3 {
@@ -39,9 +38,8 @@ pub struct S {
3938
}
4039

4140
pub struct S2 {
42-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
43-
// Expand as needed, numbers should be ascending according to the stage
44-
// through the inclusion pipeline, or according to the descriptions
41+
// Expand as needed, numbers should be ascending according to the stage
42+
// through the inclusion pipeline, or according to the descriptions
4543
}
4644

4745
pub struct S3 {

tests/source/comments-in-lists/wrap-comments-true.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ pub enum E {
1414
}
1515

1616
pub enum E2 {
17-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
18-
// Expand as needed, numbers should be ascending according to the stage
19-
// through the inclusion pipeline, or according to the descriptions
17+
// Expand as needed, numbers should be ascending according to the stage
18+
// through the inclusion pipeline, or according to the descriptions
2019
}
2120

2221
pub enum E3 {
@@ -40,9 +39,8 @@ pub struct S {
4039
}
4140

4241
pub struct S2 {
43-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
44-
// Expand as needed, numbers should be ascending according to the stage
45-
// through the inclusion pipeline, or according to the descriptions
42+
// Expand as needed, numbers should be ascending according to the stage
43+
// through the inclusion pipeline, or according to the descriptions
4644
}
4745

4846
pub struct S3 {

tests/target/comments-in-lists/format-doc-comments.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ pub enum E {
2525
}
2626

2727
pub enum E2 {
28-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
29-
// Expand as needed, numbers should be ascending according to the stage
30-
// through the inclusion pipeline, or according to the descriptions
28+
// Expand as needed, numbers should be ascending according to the stage
29+
// through the inclusion pipeline, or according to the descriptions
3130
}
3231

3332
pub struct S {
@@ -42,9 +41,8 @@ pub struct S {
4241
}
4342

4443
pub struct S2 {
45-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
46-
// Expand as needed, numbers should be ascending according to the stage
47-
// through the inclusion pipeline, or according to the descriptions
44+
// Expand as needed, numbers should be ascending according to the stage
45+
// through the inclusion pipeline, or according to the descriptions
4846
}
4947

5048
fn foo(

tests/target/comments-in-lists/wrap-comments-false.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ pub enum E {
1313
}
1414

1515
pub enum E2 {
16-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
17-
// Expand as needed, numbers should be ascending according to the stage
18-
// through the inclusion pipeline, or according to the descriptions
16+
// Expand as needed, numbers should be ascending according to the stage
17+
// through the inclusion pipeline, or according to the descriptions
1918
}
2019

2120
pub struct S {
@@ -30,9 +29,8 @@ pub struct S {
3029
}
3130

3231
pub struct S2 {
33-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
34-
// Expand as needed, numbers should be ascending according to the stage
35-
// through the inclusion pipeline, or according to the descriptions
32+
// Expand as needed, numbers should be ascending according to the stage
33+
// through the inclusion pipeline, or according to the descriptions
3634
}
3735

3836
fn foo(

tests/target/comments-in-lists/wrap-comments-not-normalized.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ pub enum E {
1313
}
1414

1515
pub enum E2 {
16-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
17-
// Expand as needed, numbers should be ascending according to the stage
18-
// through the inclusion pipeline, or according to the descriptions
16+
// Expand as needed, numbers should be ascending according to the stage
17+
// through the inclusion pipeline, or according to the descriptions
1918
}
2019

2120
pub enum E3 {
@@ -41,9 +40,8 @@ pub struct S {
4140
}
4241

4342
pub struct S2 {
44-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
45-
// Expand as needed, numbers should be ascending according to the stage
46-
// through the inclusion pipeline, or according to the descriptions
43+
// Expand as needed, numbers should be ascending according to the stage
44+
// through the inclusion pipeline, or according to the descriptions
4745
}
4846

4947
pub struct S3 {

tests/target/comments-in-lists/wrap-comments-true.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ pub enum E {
1414
}
1515

1616
pub enum E2 {
17-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
18-
// Expand as needed, numbers should be ascending according to the stage
19-
// through the inclusion pipeline, or according to the descriptions
17+
// Expand as needed, numbers should be ascending according to the stage
18+
// through the inclusion pipeline, or according to the descriptions
2019
}
2120

2221
pub enum E3 {
@@ -42,9 +41,8 @@ pub struct S {
4241
}
4342

4443
pub struct S2 {
45-
// This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
46-
// Expand as needed, numbers should be ascending according to the stage
47-
// through the inclusion pipeline, or according to the descriptions
44+
// Expand as needed, numbers should be ascending according to the stage
45+
// through the inclusion pipeline, or according to the descriptions
4846
}
4947

5048
pub struct S3 {

0 commit comments

Comments
 (0)