Skip to content

Commit 93c48a0

Browse files
committed
remove stars at the beginning of multiline comments
1 parent d1eecba commit 93c48a0

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

clippy_lints/src/doc.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
109109
if comment.starts_with("/*") {
110110
let doc = &comment[3..comment.len() - 2];
111111
let mut sizes = vec![];
112-
112+
let mut contains_initial_stars = false;
113113
for line in doc.lines() {
114114
let offset = line.as_ptr() as usize - comment.as_ptr() as usize;
115115
debug_assert_eq!(offset as u32 as usize, offset);
116-
116+
contains_initial_stars |= line.trim_left().starts_with('*');
117117
// +1 for the newline
118118
sizes.push((
119119
line.len() + 1,
@@ -123,8 +123,25 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
123123
},
124124
));
125125
}
126-
127-
return (doc.to_string(), sizes);
126+
if !contains_initial_stars {
127+
return (doc.to_string(), sizes);
128+
}
129+
// remove the initial '*'s if any
130+
let mut no_stars = String::with_capacity(doc.len());
131+
for line in doc.lines() {
132+
let mut chars = line.chars();
133+
while let Some(c) = chars.next() {
134+
if c.is_whitespace() {
135+
no_stars.push(c);
136+
} else {
137+
no_stars.push(if c == '*' { ' ' } else { c });
138+
break;
139+
}
140+
}
141+
no_stars.push_str(chars.as_str());
142+
no_stars.push('\n');
143+
}
144+
return (no_stars, sizes);
128145
}
129146

130147
panic!("not a doc-comment: {}", comment);

tests/ui/doc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,9 @@ fn issue_902_comment() {}
153153
/// }
154154
/// ```
155155
fn issue_1469() {}
156+
157+
/**
158+
* This is a doc comment that should not be a list
159+
*This would also be an error under a strict common mark interpretation
160+
*/
161+
fn issue_1920() {}

0 commit comments

Comments
 (0)