Skip to content

Commit 2449791

Browse files
committed
Fix a crash/mislex when more than one frontmatter closing possibility is considered
1 parent 29005cb commit 2449791

File tree

1 file changed

+3
-1
lines changed
  • compiler/rustc_lexer/src

1 file changed

+3
-1
lines changed

compiler/rustc_lexer/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,16 @@ impl Cursor<'_> {
599599
if potential_closing.is_none() {
600600
// a less fortunate recovery if all else fails which finds any dashes preceded by whitespace
601601
// on a standalone line. Might be wrong.
602+
let mut base_index = 0;
602603
while let Some(closing) = rest.find("---") {
603604
let preceding_chars_start = rest[..closing].rfind("\n").map_or(0, |i| i + 1);
604605
if rest[preceding_chars_start..closing].chars().all(is_horizontal_whitespace) {
605606
// candidate found
606-
potential_closing = Some(closing);
607+
potential_closing = Some(closing + base_index);
607608
break;
608609
} else {
609610
rest = &rest[closing + 3..];
611+
base_index += closing + 3;
610612
}
611613
}
612614
}

0 commit comments

Comments
 (0)