Auto merge of #121636 - matthiaskrgr:rollup-1tt2o5n, r=matthiaskrgr

Rollup of 6 pull requests

Successful merges:

 - #121389 (llvm-wrapper: fix few warnings)
 - #121493 (By changing some attributes to only_local, reducing encoding attributes in the crate metadate.)
 - #121615 (Move `emit_stashed_diagnostic` call in rustfmt.)
 - #121617 (Actually use the right closure kind when checking async Fn goals)
 - #121628 (Do not const prop unions)
 - #121629 (fix some references to no-longer-existing ReprOptions.layout_seed)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-02-26 17:14:13 +00:00
commit f9dba393ea
5 changed files with 35 additions and 19 deletions

View File

@ -109,7 +109,7 @@ fn format_project<T: FormatHandler>(
let main_file = input.file_name(); let main_file = input.file_name();
let input_is_stdin = main_file == FileName::Stdin; let input_is_stdin = main_file == FileName::Stdin;
let parse_session = ParseSess::new(config)?; let mut parse_session = ParseSess::new(config)?;
if config.skip_children() && parse_session.ignore_file(&main_file) { if config.skip_children() && parse_session.ignore_file(&main_file) {
return Ok(FormatReport::new()); return Ok(FormatReport::new());
} }
@ -117,11 +117,21 @@ fn format_project<T: FormatHandler>(
// Parse the crate. // Parse the crate.
let mut report = FormatReport::new(); let mut report = FormatReport::new();
let directory_ownership = input.to_directory_ownership(); let directory_ownership = input.to_directory_ownership();
let krate = match Parser::parse_crate(input, &parse_session) {
Ok(krate) => krate, // rustfmt doesn't use `run_compiler` like other tools, so it must emit any
// Surface parse error via Session (errors are merged there from report) // stashed diagnostics itself, otherwise the `DiagCtxt` will assert when
Err(e) => { // dropped. The final result here combines the parsing result and the
let forbid_verbose = input_is_stdin || e != ParserError::ParsePanicError; // `emit_stashed_diagnostics` result.
let parse_res = Parser::parse_crate(input, &parse_session);
let stashed_res = parse_session.emit_stashed_diagnostics();
let krate = match (parse_res, stashed_res) {
(Ok(krate), None) => krate,
(parse_res, _) => {
// Surface parse error via Session (errors are merged there from report).
let forbid_verbose = match parse_res {
Err(e) if e != ParserError::ParsePanicError => true,
_ => input_is_stdin,
};
should_emit_verbose(forbid_verbose, config, || { should_emit_verbose(forbid_verbose, config, || {
eprintln!("The Rust parser panicked"); eprintln!("The Rust parser panicked");
}); });

View File

@ -162,22 +162,14 @@ 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);
// rustfmt doesn't use `run_compiler` like other tools, so it must emit
// any stashed diagnostics itself, otherwise the `DiagCtxt` will assert
// 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); let err = Err(ParserError::ParsePanicError);
match (parse_res, stashed_res) { match catch_unwind(move || parser.parse_crate_mod()) {
(Ok(Ok(k)), None) => Ok(k), Ok(Ok(k)) => Ok(k),
(Ok(Ok(_)), Some(_guar)) => err, Ok(Err(db)) => {
(Ok(Err(db)), _) => {
db.emit(); db.emit();
err err
} }
(Err(_), _) => err, Err(_) => err,
} }
} }
} }

View File

@ -6,7 +6,7 @@
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter}; use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter};
use rustc_errors::translation::Translate; use rustc_errors::translation::Translate;
use rustc_errors::{ use rustc_errors::{
ColorConfig, DiagCtxt, Diagnostic, DiagnosticBuilder, Level as DiagnosticLevel, ColorConfig, DiagCtxt, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Level as DiagnosticLevel,
}; };
use rustc_session::parse::ParseSess as RawParseSess; use rustc_session::parse::ParseSess as RawParseSess;
use rustc_span::{ use rustc_span::{
@ -230,6 +230,10 @@ pub(crate) fn ignore_file(&self, path: &FileName) -> bool {
self.ignore_path_set.as_ref().is_match(path) self.ignore_path_set.as_ref().is_match(path)
} }
pub(crate) fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
self.parse_sess.dcx.emit_stashed_diagnostics()
}
pub(crate) fn set_silent_emitter(&mut self) { pub(crate) fn set_silent_emitter(&mut self) {
self.parse_sess.dcx = DiagCtxt::with_emitter(silent_emitter()); self.parse_sess.dcx = DiagCtxt::with_emitter(silent_emitter());
} }

View File

@ -62,3 +62,10 @@ fn crate_parsing_stashed_diag() {
let filename = "tests/parser/stashed-diag.rs"; let filename = "tests/parser/stashed-diag.rs";
assert_parser_error(filename); assert_parser_error(filename);
} }
#[test]
fn crate_parsing_stashed_diag2() {
// See also https://github.com/rust-lang/rust/issues/121517
let filename = "tests/parser/stashed-diag2.rs";
assert_parser_error(filename);
}

View File

@ -0,0 +1,3 @@
trait Trait<'1> { s> {}
fn main() {}