Skip to content

Commit 98efebd

Browse files
authored
Recognize when a block comment has been ended inside a string literal (#4320)
* Recognize when a block comment has been ended inside a string literal Closes #4312 * fixup! Recognize when a block comment has been ended inside a string literal
1 parent e438529 commit 98efebd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/formatting/comment.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,9 @@ where
13401340
char_kind = FullCodeCharKind::InStringCommented;
13411341
if chr == '"' {
13421342
CharClassesStatus::BlockComment(deepness)
1343+
} else if chr == '*' && self.base.peek().map(RichChar::get_char) == Some('/') {
1344+
char_kind = FullCodeCharKind::InComment;
1345+
CharClassesStatus::BlockCommentClosing(deepness - 1)
13431346
} else {
13441347
CharClassesStatus::StringInBlockComment(deepness)
13451348
}

tests/target/issue-4312.rs

Lines changed: 8 additions & 0 deletions
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)