Merge pull request #2155 from topecongiro/issue-1603
Prevent panicking by a nested comment
This commit is contained in:
commit
c0e537d227
@ -572,10 +572,12 @@ fn next(&mut self) -> Option<Self::Item> {
|
||||
let comment_end = match self.inner.peek() {
|
||||
Some(..) => {
|
||||
let mut block_open_index = post_snippet.find("/*");
|
||||
// check if it really is a block comment (and not //*)
|
||||
// check if it really is a block comment (and not `//*` or a nested comment)
|
||||
if let Some(i) = block_open_index {
|
||||
if i > 0 && &post_snippet[i - 1..i] == "/" {
|
||||
block_open_index = None;
|
||||
match post_snippet.find("/") {
|
||||
Some(j) if j < i => block_open_index = None,
|
||||
_ if i > 0 && &post_snippet[i - 1..i] == "/" => block_open_index = None,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
let newline_index = post_snippet.find('\n');
|
||||
|
@ -81,3 +81,10 @@ fn some_fn4()
|
||||
/* some comment some comment some comment some comment some comment some comment some comment */
|
||||
{
|
||||
}
|
||||
|
||||
// #1603
|
||||
pub enum Foo {
|
||||
A, // `/** **/`
|
||||
B, // `/*!`
|
||||
C,
|
||||
}
|
||||
|
@ -86,3 +86,10 @@ fn some_fn4()
|
||||
// some comment
|
||||
{
|
||||
}
|
||||
|
||||
// #1603
|
||||
pub enum Foo {
|
||||
A, // `/** **/`
|
||||
B, // `/*!`
|
||||
C,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user