Skip to content

Commit 8a96884

Browse files
committed
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.
1 parent 57ee5cf commit 8a96884

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,12 @@ impl Handler {
11331133
);
11341134
std::mem::take(&mut self.inner.borrow_mut().fulfilled_expectations)
11351135
}
1136+
1137+
pub fn flush_delayed(&self) {
1138+
let mut inner = self.inner.lock();
1139+
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());
1140+
inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
1141+
}
11361142
}
11371143

11381144
impl HandlerInner {

compiler/rustc_interface/src/queries.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ impl<'tcx> Queries<'tcx> {
246246
// Don't do code generation if there were any errors
247247
self.session().compile_status()?;
248248

249+
self.session().diagnostic().flush_delayed();
250+
249251
// Hook for UI tests.
250252
Self::check_for_rustc_errors_attr(tcx);
251253

0 commit comments

Comments
 (0)