Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3986e69

Browse files
Alan Dutopecongiro
Alan Du
authored andcommitted
Do not count /*/ as both start and end comment (rust-lang#3185)
1 parent f10b225 commit 3986e69

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/comment.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,23 @@ fn identify_comment(
312312
let closer = style.closer().trim_left();
313313
let mut closing_symbol_offset = 0;
314314
let mut hbl = false;
315+
let mut first = true;
315316
for line in orig.lines() {
316317
closing_symbol_offset += compute_len(&orig[closing_symbol_offset..], line);
317-
let trimmed_line = line.trim_left();
318+
let mut trimmed_line = line.trim_left();
318319
if !trimmed_line.starts_with('*')
319320
&& !trimmed_line.starts_with("//")
320321
&& !trimmed_line.starts_with("/*")
321322
{
322323
hbl = true;
323324
}
325+
326+
// Remove opener from consideration when searching for closer
327+
if first {
328+
let opener = style.opener().trim_right();
329+
trimmed_line = &trimmed_line[opener.len()..];
330+
first = false;
331+
}
324332
if trimmed_line.ends_with(closer) {
325333
break;
326334
}

tests/target/issue-3184.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*/
2+
struct Error{
3+
message: String,
4+
}
5+
*/

0 commit comments

Comments
 (0)