From 8a96884981c97c4c35e304004290271308a67637 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:56:05 +0200 Subject: [PATCH] Flush delayed bugs before codegen Sometimes it can happen that invalid code like a TyKind::Error makes its way through the compiler without triggering any errors (this is always a bug in rustc but bugs do happen sometimes :)). These ICEs will manifest in the backend like as cg_llvm not being able to get the layout of `[type error]`, which makes it hard to debug. By flushing before codegen, we display all the delayed bugs, making it easier to trace it to the root of the problem. --- compiler/rustc_errors/src/lib.rs | 6 ++++++ compiler/rustc_interface/src/queries.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 4d262ae0f5e..b4e99225f81 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1133,6 +1133,12 @@ pub fn steal_fulfilled_expectation_ids(&self) -> FxHashSet { ); std::mem::take(&mut self.inner.borrow_mut().fulfilled_expectations) } + + pub fn flush_delayed(&self) { + let mut inner = self.inner.lock(); + let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new()); + inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued"); + } } impl HandlerInner { diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 6c725a01b53..60ed48d8988 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -246,6 +246,8 @@ pub fn ongoing_codegen(&'tcx self) -> Result<&Query>> { // Don't do code generation if there were any errors self.session().compile_status()?; + self.session().diagnostic().flush_delayed(); + // Hook for UI tests. Self::check_for_rustc_errors_attr(tcx);