Skip to content

Commit 9ec772e

Browse files
authored
Rollup merge of #102373 - Nilstrieb:cannot-get-layout-of-branch-error, r=cjgillot
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. I tried this on #102366 and it showed tons of of delayed bugs and no error in cg_llvm, so it seems to be working.
2 parents c07ebeb + e8f1bfe commit 9ec772e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

compiler/rustc_errors/src/lib.rs

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

11391145
impl HandlerInner {

compiler/rustc_interface/src/queries.rs

+4
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ impl<'tcx> Queries<'tcx> {
246246
// Don't do code generation if there were any errors
247247
self.session().compile_status()?;
248248

249+
// If we have any delayed bugs, for example because we created TyKind::Error earlier,
250+
// it's likely that codegen will only cause more ICEs, obscuring the original problem
251+
self.session().diagnostic().flush_delayed();
252+
249253
// Hook for UI tests.
250254
Self::check_for_rustc_errors_attr(tcx);
251255

0 commit comments

Comments
 (0)