File tree Expand file tree Collapse file tree 3 files changed +104
-7
lines changed Expand file tree Collapse file tree 3 files changed +104
-7
lines changed Original file line number Diff line number Diff line change @@ -948,25 +948,30 @@ 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
+ (
970
+ blank,
971
+ trim_end_unless_two_whitespaces ( left_trimmed, is_doc_comment) ,
972
+ )
969
973
} )
974
+ . map ( |( b, l) | format ! ( "{}{}" , b, l) )
970
975
. collect ( ) ;
971
976
lines. join ( & format ! ( "\n {}" , offset. to_string( config) ) )
972
977
}
Original file line number Diff line number Diff line change
1
+ // Ensure multiline comments are indented properly,
2
+ // incluyding when second line is prefixed by tab or at the beginning of the line
3
+
4
+ /* First comment line
5
+ * second comment line - no prefix
6
+ * last comment line */
7
+
8
+ /* First comment line
9
+ * second comment line - blank prefix
10
+ * last comment line */
11
+
12
+ /* First comment line
13
+ * second comment line - tab prefix
14
+ * last comment line */
15
+
16
+ /* First comment line
17
+ * second comment line - blank prefix
18
+ * last comment line - no prefix */
19
+
20
+ /* First comment line
21
+ * second comment line - blank prefix
22
+ * last comment line */
23
+
24
+ type T1 = TT<
25
+ u32, /* First comment line
26
+ * second comment line - no prefix
27
+ * last comment line */
28
+ >;
29
+
30
+ type T2 = TT<
31
+ u32, /* First comment line
32
+ * second comment line - blank prefix
33
+ * last comment line */
34
+ >;
35
+
36
+ type T2 = TT<
37
+ u32, /* First comment line
38
+ * second comment line - tab prefix
39
+ * last comment line */
40
+ >;
41
+
42
+ type T3 = TT<
43
+ u32, /* First comment line
44
+ * second comment line - tab prefix
45
+ * last comment line */
46
+ >;
Original file line number Diff line number Diff line change
1
+ // Ensure multiline comments are indented properly,
2
+ // incluyding when second line is prefixed by tab or at the beginning of the line
3
+
4
+ /* First comment line
5
+ * second comment line - no prefix
6
+ * last comment line */
7
+
8
+ /* First comment line
9
+ * second comment line - blank prefix
10
+ * last comment line */
11
+
12
+ /* First comment line
13
+ * second comment line - tab prefix
14
+ * last comment line */
15
+
16
+ /* First comment line
17
+ * second comment line - blank prefix
18
+ * last comment line - no prefix */
19
+
20
+ /* First comment line
21
+ * second comment line - blank prefix
22
+ * last comment line */
23
+
24
+ type T1 = TT<
25
+ u32, /* First comment line
26
+ * second comment line - no prefix
27
+ * last comment line */
28
+ >;
29
+
30
+ type T2 = TT<
31
+ u32, /* First comment line
32
+ * second comment line - blank prefix
33
+ * last comment line */
34
+ >;
35
+
36
+ type T2 = TT<
37
+ u32, /* First comment line
38
+ * second comment line - tab prefix
39
+ * last comment line */
40
+ >;
41
+
42
+ type T3 = TT<
43
+ u32, /* First comment line
44
+ * second comment line - tab prefix
45
+ * last comment line */
46
+ >;
You can’t perform that action at this time.
0 commit comments