Skip to content

Commit c0e537d

Browse files
authored
Merge pull request #2155 from topecongiro/issue-1603
Prevent panicking by a nested comment
2 parents 1a69aeb + 95c7325 commit c0e537d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/lists.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,12 @@ where
572572
let comment_end = match self.inner.peek() {
573573
Some(..) => {
574574
let mut block_open_index = post_snippet.find("/*");
575-
// check if it really is a block comment (and not //*)
575+
// check if it really is a block comment (and not `//*` or a nested comment)
576576
if let Some(i) = block_open_index {
577-
if i > 0 && &post_snippet[i - 1..i] == "/" {
578-
block_open_index = None;
577+
match post_snippet.find("/") {
578+
Some(j) if j < i => block_open_index = None,
579+
_ if i > 0 && &post_snippet[i - 1..i] == "/" => block_open_index = None,
580+
_ => (),
579581
}
580582
}
581583
let newline_index = post_snippet.find('\n');

tests/source/comment.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,10 @@ fn some_fn4()
8181
/* some comment some comment some comment some comment some comment some comment some comment */
8282
{
8383
}
84+
85+
// #1603
86+
pub enum Foo {
87+
A, // `/** **/`
88+
B, // `/*!`
89+
C,
90+
}

tests/target/comment.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@ fn some_fn4()
8686
// some comment
8787
{
8888
}
89+
90+
// #1603
91+
pub enum Foo {
92+
A, // `/** **/`
93+
B, // `/*!`
94+
C,
95+
}

0 commit comments

Comments
 (0)