Merge pull request #4702 from RalfJung/stashed-diag

emit stashed diagnostics before flushing delayed errors
This commit is contained in:
Ralf Jung 2025-11-17 11:51:06 +00:00 committed by GitHub
commit ffac3a6a9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 6 deletions

View file

@ -158,19 +158,24 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
_: &rustc_interface::interface::Compiler,
tcx: TyCtxt<'tcx>,
) -> Compilation {
// Compilation is done, interpretation is starting. Deal with diagnostics from the
// compilation part. We cannot call `sess.finish_diagnostics()` as then "aborting due to
// previous errors" gets printed twice.
tcx.dcx().emit_stashed_diagnostics();
tcx.dcx().abort_if_errors();
tcx.dcx().flush_delayed();
// Miri is taking over. Start logging.
init_late_loggers(&EarlyDiagCtxt::new(tcx.sess.opts.error_format), tcx);
// Find the entry point.
if !tcx.crate_types().contains(&CrateType::Executable) {
tcx.dcx().fatal("miri only makes sense on bin crates");
}
let early_dcx = EarlyDiagCtxt::new(tcx.sess.opts.error_format);
init_late_loggers(&early_dcx, tcx);
let (entry_def_id, entry_type) = entry_fn(tcx);
let mut config = self.miri_config.take().expect("after_analysis must only be called once");
// Obtain and complete the Miri configuration.
let mut config = self.miri_config.take().expect("after_analysis must only be called once");
// Add filename to `miri` arguments.
config.args.insert(0, tcx.sess.io.input.filestem().to_string());
@ -179,6 +184,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
env::set_current_dir(cwd).unwrap();
}
// Emit warnings for some unusual configurations.
if tcx.sess.opts.optimize != OptLevel::No {
tcx.dcx().warn("Miri does not support optimizations: the opt-level is ignored. The only effect \
of selecting a Cargo profile that enables optimizations (such as --release) is to apply \
@ -193,6 +199,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
optimizations is usually marginal at best.");
}
// Invoke the interpreter.
let res = if config.genmc_config.is_some() {
assert!(self.many_seeds.is_none());
run_genmc_mode(tcx, &config, |genmc_ctx: Rc<GenmcCtx>| {
@ -209,7 +216,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
} else {
miri::eval_entry(tcx, entry_def_id, entry_type, &config, None)
};
// Process interpreter result.
if let Err(return_code) = res {
tcx.dcx().abort_if_errors();
exit(return_code.get());

View file

@ -0,0 +1,10 @@
// This test seems to involve a "stashed diagnostic" (or at least it used to at the time of
// writing). Ensure we handle that correctly.
pub trait Trait {
type Assoc: Assoc;
}
pub trait Assoc {}
fn main() {}