Skip to content

Commit

Permalink
Recognize when a block comment has been ended inside a string literal (
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinYing-Li authored and calebcartwright committed Apr 22, 2021
1 parent 58157bb commit dac2423
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ where
char_kind = FullCodeCharKind::InStringCommented;
if chr == '"' {
CharClassesStatus::BlockComment(deepness)
} else if chr == '*' && self.base.peek().map(RichChar::get_char) == Some('/') {
char_kind = FullCodeCharKind::InComment;
CharClassesStatus::BlockCommentClosing(deepness - 1)
} else {
CharClassesStatus::StringInBlockComment(deepness)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/source/issue-4312.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
/* " */
println!("Hello, world!");
/* abc " */
println!("Hello, world!");
/* " abc */
println!("Hello, world!");
}
8 changes: 8 additions & 0 deletions tests/target/issue-4312.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
/* " */
println!("Hello, world!");
/* abc " */
println!("Hello, world!");
/* " abc */
println!("Hello, world!");
}

0 comments on commit dac2423

Please sign in to comment.