Skip to content

Commit 36f93cb

Browse files
committed
Split delayed bugs into has-errored and will-error halves.
This commit adds new `{span_,}assert_has_errors` methods implementing the simpler has-errored cases, and leaves the existing `{span_,}delayed_bug` methods for the will-error cases. It also converts as many cases as possible to has-errored. I did this by converting every case to has-errored, then running tests and converting back to will-error every case that caused an assertion in the test suite. The test suite doesn't have perfect coverage so it's possible that there are a few more has-errored cases that will need conversion back to will-error. Also, some of the will-error cases might actually be a mixture of has-errored and will-error. But it's hard to do this perfectly without carefully going through every individual case, which would be painful, and an imperfect split still gets most of the benefits.
1 parent f484cf9 commit 36f93cb

File tree

92 files changed

+266
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+266
-200
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
pub trait LayoutCalculator {
3333
type TargetDataLayoutRef: Borrow<TargetDataLayout>;
3434

35-
fn delayed_bug(&self, txt: String);
35+
fn assert_has_errors(&self, txt: String);
3636
fn current_data_layout(&self) -> Self::TargetDataLayoutRef;
3737

3838
fn scalar_pair<FieldIdx: Idx, VariantIdx: Idx>(
@@ -259,7 +259,7 @@ pub trait LayoutCalculator {
259259
let only_variant = &variants[VariantIdx::new(0)];
260260
for field in only_variant {
261261
if field.is_unsized() {
262-
self.delayed_bug("unsized field in union".to_string());
262+
self.assert_has_errors("unsized field in union".to_string());
263263
}
264264

265265
align = align.max(field.align);
@@ -1092,7 +1092,7 @@ fn univariant<
10921092
for &i in &inverse_memory_index {
10931093
let field = &fields[i];
10941094
if !sized {
1095-
this.delayed_bug(format!(
1095+
this.assert_has_errors(format!(
10961096
"univariant: field #{} comes after unsized field",
10971097
offsets.len(),
10981098
));

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
112112
sig_id.ok_or_else(|| {
113113
self.tcx
114114
.dcx()
115-
.span_delayed_bug(span, "LoweringContext: couldn't resolve delegation item")
115+
.span_assert_has_errors(span, "LoweringContext: couldn't resolve delegation item")
116116
})
117117
}
118118

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
323323
)
324324
}
325325
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
326-
ExprKind::Err => {
327-
hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Err"))
328-
}
326+
ExprKind::Err => hir::ExprKind::Err(
327+
self.dcx().span_assert_has_errors(e.span, "lowered ExprKind::Err"),
328+
),
329329
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
330330

331331
ExprKind::Paren(_) | ExprKind::ForLoop { .. } => {

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn make_count<'hir>(
267267
ctx.expr(
268268
sp,
269269
hir::ExprKind::Err(
270-
ctx.dcx().span_delayed_bug(sp, "lowered bad format_args count"),
270+
ctx.dcx().span_assert_has_errors(sp, "lowered bad format_args count"),
271271
),
272272
)
273273
}
@@ -306,7 +306,9 @@ fn make_format_spec<'hir>(
306306
}
307307
Err(_) => ctx.expr(
308308
sp,
309-
hir::ExprKind::Err(ctx.dcx().span_delayed_bug(sp, "lowered bad format_args count")),
309+
hir::ExprKind::Err(
310+
ctx.dcx().span_assert_has_errors(sp, "lowered bad format_args count"),
311+
),
310312
),
311313
};
312314
let &FormatOptions {

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(super) fn index_hir<'hir>(
6161
if let Node::Err(span) = node.node {
6262
let hir_id = HirId { owner: item.def_id(), local_id };
6363
let msg = format!("ID {hir_id} not encountered when visiting item HIR");
64-
tcx.dcx().span_delayed_bug(*span, msg);
64+
tcx.dcx().span_assert_has_errors(*span, msg);
6565
}
6666
}
6767

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
266266
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
267267
|this| match ty {
268268
None => {
269-
let guar = this.dcx().span_delayed_bug(
269+
let guar = this.dcx().span_assert_has_errors(
270270
span,
271271
"expected to lower type alias type, but it was missing",
272272
);
@@ -925,7 +925,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
925925
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
926926
|this| match ty {
927927
None => {
928-
let guar = this.dcx().span_delayed_bug(
928+
let guar = this.dcx().span_assert_has_errors(
929929
i.span,
930930
"expected to lower associated type, but it was missing",
931931
);
@@ -1068,7 +1068,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10681068
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
10691069
match block {
10701070
Some(block) => self.lower_block_expr(block),
1071-
None => self.expr_err(span, self.dcx().span_delayed_bug(span, "no block")),
1071+
None => self.expr_err(span, self.dcx().span_assert_has_errors(span, "no block")),
10721072
}
10731073
}
10741074

@@ -1078,7 +1078,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
10781078
&[],
10791079
match expr {
10801080
Some(expr) => this.lower_expr_mut(expr),
1081-
None => this.expr_err(span, this.dcx().span_delayed_bug(span, "no block")),
1081+
None => {
1082+
this.expr_err(span, this.dcx().span_assert_has_errors(span, "no block"))
1083+
}
10821084
},
10831085
)
10841086
})

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
747747
let res = self.resolver.get_import_res(id).present_items();
748748
let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect();
749749
if res.is_empty() {
750-
self.dcx().span_delayed_bug(span, "no resolution for an import");
750+
self.dcx().span_assert_has_errors(span, "no resolution for an import");
751751
return smallvec![Res::Err];
752752
}
753753
res
@@ -1286,7 +1286,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12861286
let kind = match &t.kind {
12871287
TyKind::Infer => hir::TyKind::Infer,
12881288
TyKind::Err => {
1289-
hir::TyKind::Err(self.dcx().span_delayed_bug(t.span, "TyKind::Err lowered"))
1289+
hir::TyKind::Err(self.dcx().span_assert_has_errors(t.span, "TyKind::Err lowered"))
12901290
}
12911291
// Lower the anonymous structs or unions in a nested lowering context.
12921292
//
@@ -1499,7 +1499,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14991499
}
15001500
TyKind::MacCall(_) => panic!("`TyKind::MacCall` should have been expanded by now"),
15011501
TyKind::CVarArgs => {
1502-
let guar = self.dcx().span_delayed_bug(
1502+
let guar = self.dcx().span_assert_has_errors(
15031503
t.span,
15041504
"`TyKind::CVarArgs` should have been handled elsewhere",
15051505
);
@@ -1643,8 +1643,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16431643
if let Some(old_def_id) = self.orig_opt_local_def_id(param) {
16441644
old_def_id
16451645
} else {
1646-
self.dcx()
1647-
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1646+
self.dcx().span_assert_has_errors(
1647+
lifetime.ident.span,
1648+
"no def-id for fresh lifetime",
1649+
);
16481650
continue;
16491651
}
16501652
}
@@ -2576,7 +2578,7 @@ impl<'hir> GenericArgsCtor<'hir> {
25762578
let span = lcx.lower_span(span);
25772579

25782580
let Some(host_param_id) = lcx.host_param_id else {
2579-
lcx.dcx().span_delayed_bug(
2581+
lcx.dcx().span_assert_has_errors(
25802582
span,
25812583
"no host param id for call in const yet no errors reported",
25822584
);

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
627627
_,
628628
) => {
629629
// HIR lowering sometimes doesn't catch this in erroneous
630-
// programs, so we need to use span_delayed_bug here. See #82126.
631-
self.dcx().span_delayed_bug(
630+
// programs, so we need to use span_assert_has_errors here. See #82126.
631+
self.dcx().span_assert_has_errors(
632632
hir_arg.span(),
633633
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
634634
);

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
316316
.and(type_op::normalize::Normalize::new(ty))
317317
.fully_perform(self.infcx, span)
318318
else {
319-
tcx.dcx().span_delayed_bug(span, format!("failed to normalize {ty:?}"));
319+
tcx.dcx().span_assert_has_errors(span, format!("failed to normalize {ty:?}"));
320320
continue;
321321
};
322322
constraints.extend(c);

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
152152
// Equate expected input tys with those in the MIR.
153153
for (argument_index, &normalized_input_ty) in normalized_input_tys.iter().enumerate() {
154154
if argument_index + 1 >= body.local_decls.len() {
155-
self.tcx()
156-
.dcx()
157-
.span_delayed_bug(body.span, "found more normalized_input_ty than local_decls");
155+
self.tcx().dcx().span_assert_has_errors(
156+
body.span,
157+
"found more normalized_input_ty than local_decls",
158+
);
158159
break;
159160
}
160161

0 commit comments

Comments
 (0)