Explicitly call emit_stashed_diagnostics
.
Commit 72b172b
in #121206 changed things so that
`emit_stashed_diagnostics` is only called from `run_compiler`. But
rustfmt doesn't use `run_compiler`, so it needs to call
`emit_stashed_diagnostics` itself to avoid an abort in
`DiagCtxtInner::drop` when stashed diagnostics occur.
Fixes #121450.
This commit is contained in:
parent
163c3ebf52
commit
ce71137b96
@ -163,13 +163,21 @@ fn parse_crate_inner(input: Input, sess: &'a ParseSess) -> Result<ast::Crate, Pa
|
|||||||
fn parse_crate_mod(&mut self) -> Result<ast::Crate, ParserError> {
|
fn parse_crate_mod(&mut self) -> Result<ast::Crate, ParserError> {
|
||||||
let mut parser = AssertUnwindSafe(&mut self.parser);
|
let mut parser = AssertUnwindSafe(&mut self.parser);
|
||||||
|
|
||||||
match catch_unwind(move || parser.parse_crate_mod()) {
|
// rustfmt doesn't use `run_compiler` like other tools, so it must emit
|
||||||
Ok(Ok(k)) => Ok(k),
|
// any stashed diagnostics itself, otherwise the `DiagCtxt` will assert
|
||||||
Ok(Err(db)) => {
|
// when dropped. The final result here combines the parsing result and
|
||||||
|
// the `emit_stashed_diagnostics` result.
|
||||||
|
let parse_res = catch_unwind(move || parser.parse_crate_mod());
|
||||||
|
let stashed_res = self.parser.dcx().emit_stashed_diagnostics();
|
||||||
|
let err = Err(ParserError::ParsePanicError);
|
||||||
|
match (parse_res, stashed_res) {
|
||||||
|
(Ok(Ok(k)), None) => Ok(k),
|
||||||
|
(Ok(Ok(_)), Some(_guar)) => err,
|
||||||
|
(Ok(Err(db)), _) => {
|
||||||
db.emit();
|
db.emit();
|
||||||
Err(ParserError::ParseError)
|
err
|
||||||
}
|
}
|
||||||
Err(_) => Err(ParserError::ParsePanicError),
|
(Err(_), _) => err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,3 +55,10 @@ fn crate_parsing_errors_on_unclosed_delims() {
|
|||||||
let filename = "tests/parser/unclosed-delims/issue_4466.rs";
|
let filename = "tests/parser/unclosed-delims/issue_4466.rs";
|
||||||
assert_parser_error(filename);
|
assert_parser_error(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn crate_parsing_stashed_diag() {
|
||||||
|
// See also https://github.com/rust-lang/rust/issues/121450
|
||||||
|
let filename = "tests/parser/stashed-diag.rs";
|
||||||
|
assert_parser_error(filename);
|
||||||
|
}
|
||||||
|
3
tests/parser/stashed-diag.rs
Normal file
3
tests/parser/stashed-diag.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#![u={static N;}]
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user