File tree 7 files changed +251
-23
lines changed
7 files changed +251
-23
lines changed Original file line number Diff line number Diff line change @@ -1374,17 +1374,21 @@ fn format_empty_struct_or_tuple(
1374
1374
result. push_str ( & offset. to_string_with_newline ( context. config ) )
1375
1375
}
1376
1376
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) {
1378
1381
Some ( ref s) if s. is_empty ( ) => ( ) ,
1379
1382
Some ( ref s) => {
1380
- if !is_single_line ( s) || first_line_contains_single_line_comment ( s) {
1383
+ let is_multi_line = !is_single_line ( s) ;
1384
+ if is_multi_line || first_line_contains_single_line_comment ( s) {
1381
1385
let nested_indent_str = offset
1382
1386
. block_indent ( context. config )
1383
1387
. to_string_with_newline ( context. config ) ;
1384
1388
result. push_str ( & nested_indent_str) ;
1385
1389
}
1386
1390
result. push_str ( s) ;
1387
- if last_line_contains_single_line_comment ( s) {
1391
+ if is_multi_line || last_line_contains_single_line_comment ( s) {
1388
1392
result. push_str ( & offset. to_string_with_newline ( context. config ) ) ;
1389
1393
}
1390
1394
}
Original file line number Diff line number Diff line change
1
+ struct Struct {
2
+ // Multiline comment
3
+ // should be formatted
4
+ // properly.
5
+ }
6
+
7
+ struct Struct2 {
8
+ // This formatting
9
+ // Should be changed
10
+ }
11
+
12
+ struct Struct3 (
13
+ // This
14
+ // is
15
+ // correct
16
+ ) ;
17
+
18
+ struct Struct4 (
19
+ // This
20
+ // is
21
+ // not
22
+ // correct
23
+ ) ;
24
+
25
+ struct Struct5 {
26
+ /*
27
+ Comment block
28
+ with many lines.
29
+ */
30
+ }
31
+
32
+ struct Struct6 (
33
+ /*
34
+ Comment block
35
+ with many lines.
36
+ */
37
+ ) ;
38
+
39
+ struct Struct7 {
40
+ /*
41
+ Invalid
42
+ format
43
+ */
44
+ }
45
+
46
+ struct Struct8 (
47
+ /*
48
+ Invalid
49
+ format
50
+ */
51
+ ) ;
52
+
53
+ struct Struct9 { /* bar */ }
54
+
55
+ struct Struct10 { /* bar
56
+ baz
57
+ */ }
58
+
59
+ mod module {
60
+ struct Struct {
61
+ // Multiline comment
62
+ // should be formatted
63
+ // properly.
64
+ }
65
+
66
+ struct Struct2 {
67
+ // This formatting
68
+ // Should be changed
69
+ }
70
+
71
+ struct Struct3 (
72
+ // This
73
+ // is
74
+ // correct
75
+ ) ;
76
+
77
+ struct Struct4 (
78
+ // This
79
+ // is
80
+ // not
81
+ // correct
82
+ ) ;
83
+
84
+ struct Struct5 {
85
+ /*
86
+ Comment block
87
+ with many lines.
88
+ */
89
+ }
90
+
91
+ struct Struct6 (
92
+ /*
93
+ Comment block
94
+ with many lines.
95
+ */
96
+ ) ;
97
+
98
+ struct Struct7 {
99
+ /*
100
+ Invalid
101
+ format
102
+ */
103
+ }
104
+
105
+ struct Struct8 (
106
+ /*
107
+ Invalid
108
+ format
109
+ */
110
+ ) ;
111
+
112
+ struct Struct9 { /* bar */ }
113
+ }
Original file line number Diff line number Diff line change @@ -25,9 +25,8 @@ pub enum E {
25
25
}
26
26
27
27
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
31
30
}
32
31
33
32
pub struct S {
@@ -42,9 +41,8 @@ pub struct S {
42
41
}
43
42
44
43
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
48
46
}
49
47
50
48
fn foo (
Original file line number Diff line number Diff line change @@ -13,9 +13,8 @@ pub enum E {
13
13
}
14
14
15
15
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
19
18
}
20
19
21
20
pub struct S {
@@ -30,9 +29,8 @@ pub struct S {
30
29
}
31
30
32
31
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
36
34
}
37
35
38
36
fn foo (
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ pub enum E {
14
14
15
15
pub enum E2 {
16
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
17
+ // Expand as needed, numbers should be ascending according to the stage
18
+ // through the inclusion pipeline, or according to the descriptions
19
19
}
20
20
21
21
pub enum E3 {
@@ -42,8 +42,8 @@ pub struct S {
42
42
43
43
pub struct S2 {
44
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
45
+ // Expand as needed, numbers should be ascending according to the stage
46
+ // through the inclusion pipeline, or according to the descriptions
47
47
}
48
48
49
49
pub struct S3 {
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ pub enum E {
15
15
16
16
pub enum E2 {
17
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
18
+ // Expand as needed, numbers should be ascending according to the stage
19
+ // through the inclusion pipeline, or according to the descriptions
20
20
}
21
21
22
22
pub enum E3 {
@@ -43,8 +43,8 @@ pub struct S {
43
43
44
44
pub struct S2 {
45
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
46
+ // Expand as needed, numbers should be ascending according to the stage
47
+ // through the inclusion pipeline, or according to the descriptions
48
48
}
49
49
50
50
pub struct S3 {
Original file line number Diff line number Diff line change
1
+ struct Struct {
2
+ // Multiline comment
3
+ // should be formatted
4
+ // properly.
5
+ }
6
+
7
+ struct Struct2 {
8
+ // This formatting
9
+ // Should be changed
10
+ }
11
+
12
+ struct Struct3 (
13
+ // This
14
+ // is
15
+ // correct
16
+ ) ;
17
+
18
+ struct Struct4 (
19
+ // This
20
+ // is
21
+ // not
22
+ // correct
23
+ ) ;
24
+
25
+ struct Struct5 {
26
+ /*
27
+ Comment block
28
+ with many lines.
29
+ */
30
+ }
31
+
32
+ struct Struct6 (
33
+ /*
34
+ Comment block
35
+ with many lines.
36
+ */
37
+ ) ;
38
+
39
+ struct Struct7 {
40
+ /*
41
+ Invalid
42
+ format
43
+ */
44
+ }
45
+
46
+ struct Struct8 (
47
+ /*
48
+ Invalid
49
+ format
50
+ */
51
+ ) ;
52
+
53
+ struct Struct9 { /* bar */ }
54
+
55
+ struct Struct10 {
56
+ /* bar
57
+ baz
58
+ */
59
+ }
60
+
61
+ mod module {
62
+ struct Struct {
63
+ // Multiline comment
64
+ // should be formatted
65
+ // properly.
66
+ }
67
+
68
+ struct Struct2 {
69
+ // This formatting
70
+ // Should be changed
71
+ }
72
+
73
+ struct Struct3 (
74
+ // This
75
+ // is
76
+ // correct
77
+ ) ;
78
+
79
+ struct Struct4 (
80
+ // This
81
+ // is
82
+ // not
83
+ // correct
84
+ ) ;
85
+
86
+ struct Struct5 {
87
+ /*
88
+ Comment block
89
+ with many lines.
90
+ */
91
+ }
92
+
93
+ struct Struct6 (
94
+ /*
95
+ Comment block
96
+ with many lines.
97
+ */
98
+ ) ;
99
+
100
+ struct Struct7 {
101
+ /*
102
+ Invalid
103
+ format
104
+ */
105
+ }
106
+
107
+ struct Struct8 (
108
+ /*
109
+ Invalid
110
+ format
111
+ */
112
+ ) ;
113
+
114
+ struct Struct9 { /* bar */ }
115
+ }
You can’t perform that action at this time.
0 commit comments