Rollup merge of #151889 - chenyukang:yukang-fix-151882-frontmatter-ice, r=Kivooeo

Fix ICE when parsing frontmatter without newline

Fixes rust-lang/rust#151882

we can not add a normal test case for it:
- no newline at the end of file, we can bypass this with change test file name with `ignore-tidy`
- multiple errors in stderr, this conflicts with the previous bypass, seems we can not add multiple error annotations in one line

anyway, I added a `run-make` test for it.
This commit is contained in:
Jonathan Brouwer 2026-01-31 15:17:05 +01:00 committed by GitHub
commit 874c5d2275
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -623,7 +623,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
self.dcx().emit_err(errors::FrontmatterInvalidInfostring { span });
}
let last_line_start = real_s.rfind('\n').map_or(0, |i| i + 1);
let last_line_start = real_s.rfind('\n').map_or(line_end, |i| i + 1);
let content = &real_s[line_end..last_line_start];
if let Some(cr_offset) = content.find('\r') {

View file

@ -0,0 +1,19 @@
// Regression test for issue #151882
// See https://github.com/rust-lang/rust/issues/151882
//@ only-nightly
//@ needs-target-std
use run_make_support::{rfs, rustc};
fn main() {
rfs::write("test.rs", b"----");
// Ensure rustc does not ICE when parsing a file with frontmatter syntax
// that has no trailing newline
rustc()
.input("test.rs")
.run_fail()
.assert_stderr_contains("invalid infostring for frontmatter")
.assert_stderr_not_contains("unexpectedly panicked");
}