File tree 6 files changed +242
-47
lines changed
6 files changed +242
-47
lines changed Original file line number Diff line number Diff line change @@ -948,24 +948,29 @@ fn light_rewrite_comment(
948
948
config : & Config ,
949
949
is_doc_comment : bool ,
950
950
) -> String {
951
- let lines: Vec < & str > = orig
951
+ let lines: Vec < String > = orig
952
952
. lines ( )
953
953
. map ( |l| {
954
954
// This is basically just l.trim(), but in the case that a line starts
955
955
// with `*` we want to leave one space before it, so it aligns with the
956
956
// `*` in `/*`.
957
957
let first_non_whitespace = l. find ( |c| !char:: is_whitespace ( c) ) ;
958
- let left_trimmed = if let Some ( fnw) = first_non_whitespace {
959
- if l. as_bytes ( ) [ fnw] == b'*' && fnw > 0 {
960
- & l[ fnw - 1 ..]
958
+ let ( blank, left_trimmed) = if let Some ( fnw) = first_non_whitespace {
959
+ if l. as_bytes ( ) [ fnw] == b'*' {
960
+ // Ensure '*' is preceeded by blank and not by a tab.
961
+ ( " " , & l[ fnw..] )
961
962
} else {
962
- & l[ fnw..]
963
+ ( "" , & l[ fnw..] )
963
964
}
964
965
} else {
965
- ""
966
+ ( "" , "" )
966
967
} ;
967
968
// Preserve markdown's double-space line break syntax in doc comment.
968
- trim_end_unless_two_whitespaces ( left_trimmed, is_doc_comment)
969
+ format ! (
970
+ "{}{}" ,
971
+ blank,
972
+ trim_end_unless_two_whitespaces( left_trimmed, is_doc_comment) ,
973
+ )
969
974
} )
970
975
. collect ( ) ;
971
976
lines. join ( & format ! ( "\n {}" , offset. to_string( config) ) )
Original file line number Diff line number Diff line change
1
+ // rustfmt-hard_tabs: true
2
+ // Ensure multiline comments are indented properly,
3
+ // including when second line is prefixed by tab or at the beginning of the line
4
+
5
+ /* First comment line
6
+ * second comment line - no prefix
7
+ * last comment line */
8
+
9
+ /* First comment line
10
+ * second comment line - blank prefix
11
+ * last comment line */
12
+
13
+ /* First comment line
14
+ * second comment line - tab prefix
15
+ * last comment line */
16
+
17
+ /* First comment line
18
+ * second comment line - blank prefix
19
+ * last comment line - no prefix */
20
+
21
+ /* First comment line
22
+ * second comment line - blank prefix
23
+ * last comment line */
24
+
25
+ type T1 = TT<
26
+ u32, /* First comment line
27
+ * second comment line - no prefix
28
+ * last comment line */
29
+ >;
30
+
31
+ type T2 = TT<
32
+ u32, /* First comment line
33
+ * second comment line - blank prefix
34
+ * last comment line */
35
+ >;
36
+
37
+ type T2 = TT<
38
+ u32, /* First comment line
39
+ * second comment line - tab prefix
40
+ * last comment line */
41
+ >;
42
+
43
+ type T3 = TT<
44
+ u32, /* First comment line
45
+ * second comment line - tab prefix
46
+ * last comment line */
47
+ >;
Original file line number Diff line number Diff line change
1
+ // rustfmt-hard_tabs: false
2
+ // Ensure multiline comments are indented properly,
3
+ // including when second line is prefixed by tab or at the beginning of the line
4
+
5
+ /* First comment line
6
+ * second comment line - no prefix
7
+ * last comment line */
8
+
9
+ /* First comment line
10
+ * second comment line - blank prefix
11
+ * last comment line */
12
+
13
+ /* First comment line
14
+ * second comment line - tab prefix
15
+ * last comment line */
16
+
17
+ /* First comment line
18
+ * second comment line - blank prefix
19
+ * last comment line - no prefix */
20
+
21
+ /* First comment line
22
+ * second comment line - blank prefix
23
+ * last comment line */
24
+
25
+ type T1 = TT<
26
+ u32, /* First comment line
27
+ * second comment line - no prefix
28
+ * last comment line */
29
+ >;
30
+
31
+ type T2 = TT<
32
+ u32, /* First comment line
33
+ * second comment line - blank prefix
34
+ * last comment line */
35
+ >;
36
+
37
+ type T2 = TT<
38
+ u32, /* First comment line
39
+ * second comment line - tab prefix
40
+ * last comment line */
41
+ >;
42
+
43
+ type T3 = TT<
44
+ u32, /* First comment line
45
+ * second comment line - tab prefix
46
+ * last comment line */
47
+ >;
You can’t perform that action at this time.
0 commit comments