Skip to content

Commit ffac3a6

Browse files
authored
Merge pull request rust-lang#4702 from RalfJung/stashed-diag
emit stashed diagnostics before flushing delayed errors
2 parents 18d2f46 + daf7b01 commit ffac3a6

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/tools/miri/src/bin/miri.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,24 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
158158
_: &rustc_interface::interface::Compiler,
159159
tcx: TyCtxt<'tcx>,
160160
) -> Compilation {
161+
// Compilation is done, interpretation is starting. Deal with diagnostics from the
162+
// compilation part. We cannot call `sess.finish_diagnostics()` as then "aborting due to
163+
// previous errors" gets printed twice.
164+
tcx.dcx().emit_stashed_diagnostics();
161165
tcx.dcx().abort_if_errors();
162166
tcx.dcx().flush_delayed();
163167

168+
// Miri is taking over. Start logging.
169+
init_late_loggers(&EarlyDiagCtxt::new(tcx.sess.opts.error_format), tcx);
170+
171+
// Find the entry point.
164172
if !tcx.crate_types().contains(&CrateType::Executable) {
165173
tcx.dcx().fatal("miri only makes sense on bin crates");
166174
}
167-
168-
let early_dcx = EarlyDiagCtxt::new(tcx.sess.opts.error_format);
169-
init_late_loggers(&early_dcx, tcx);
170-
171175
let (entry_def_id, entry_type) = entry_fn(tcx);
172-
let mut config = self.miri_config.take().expect("after_analysis must only be called once");
173176

177+
// Obtain and complete the Miri configuration.
178+
let mut config = self.miri_config.take().expect("after_analysis must only be called once");
174179
// Add filename to `miri` arguments.
175180
config.args.insert(0, tcx.sess.io.input.filestem().to_string());
176181

@@ -179,6 +184,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
179184
env::set_current_dir(cwd).unwrap();
180185
}
181186

187+
// Emit warnings for some unusual configurations.
182188
if tcx.sess.opts.optimize != OptLevel::No {
183189
tcx.dcx().warn("Miri does not support optimizations: the opt-level is ignored. The only effect \
184190
of selecting a Cargo profile that enables optimizations (such as --release) is to apply \
@@ -193,6 +199,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
193199
optimizations is usually marginal at best.");
194200
}
195201

202+
// Invoke the interpreter.
196203
let res = if config.genmc_config.is_some() {
197204
assert!(self.many_seeds.is_none());
198205
run_genmc_mode(tcx, &config, |genmc_ctx: Rc<GenmcCtx>| {
@@ -209,7 +216,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
209216
} else {
210217
miri::eval_entry(tcx, entry_def_id, entry_type, &config, None)
211218
};
212-
219+
// Process interpreter result.
213220
if let Err(return_code) = res {
214221
tcx.dcx().abort_if_errors();
215222
exit(return_code.get());
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This test seems to involve a "stashed diagnostic" (or at least it used to at the time of
2+
// writing). Ensure we handle that correctly.
3+
4+
pub trait Trait {
5+
type Assoc: Assoc;
6+
}
7+
8+
pub trait Assoc {}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)