Skip to content

Commit dac2423

Browse files
ChinYing-Licalebcartwright
authored andcommitted
Recognize when a block comment has been ended inside a string literal (#4312)
1 parent 58157bb commit dac2423

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Diff for: src/comment.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,9 @@ where
13111311
char_kind = FullCodeCharKind::InStringCommented;
13121312
if chr == '"' {
13131313
CharClassesStatus::BlockComment(deepness)
1314+
} else if chr == '*' && self.base.peek().map(RichChar::get_char) == Some('/') {
1315+
char_kind = FullCodeCharKind::InComment;
1316+
CharClassesStatus::BlockCommentClosing(deepness - 1)
13141317
} else {
13151318
CharClassesStatus::StringInBlockComment(deepness)
13161319
}

Diff for: tests/source/issue-4312.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
/* " */
3+
println!("Hello, world!");
4+
/* abc " */
5+
println!("Hello, world!");
6+
/* " abc */
7+
println!("Hello, world!");
8+
}

Diff for: tests/target/issue-4312.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
/* " */
3+
println!("Hello, world!");
4+
/* abc " */
5+
println!("Hello, world!");
6+
/* " abc */
7+
println!("Hello, world!");
8+
}

0 commit comments

Comments
 (0)