Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ad0cc6c

Browse files
authored
Unrolled build for rust-lang#121071
Rollup merge of rust-lang#121071 - nnethercote:fewer-delayed-bugs, r=oli-obk Use fewer delayed bugs. For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites. r? `@oli-obk`
2 parents 81b757c + 05849e8 commit ad0cc6c

File tree

23 files changed

+88
-90
lines changed

23 files changed

+88
-90
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ 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(self.dcx().has_errors().unwrap()),
329327
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
330328

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

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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().has_errors().unwrap()),
10721072
}
10731073
}
10741074

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12851285
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
12861286
let kind = match &t.kind {
12871287
TyKind::Infer => hir::TyKind::Infer,
1288-
TyKind::Err => {
1289-
hir::TyKind::Err(self.dcx().span_delayed_bug(t.span, "TyKind::Err lowered"))
1290-
}
1288+
TyKind::Err => hir::TyKind::Err(self.dcx().has_errors().unwrap()),
12911289
// Lower the anonymous structs or unions in a nested lowering context.
12921290
//
12931291
// ```

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,14 @@ struct CfgChecker<'a, 'tcx> {
117117
impl<'a, 'tcx> CfgChecker<'a, 'tcx> {
118118
#[track_caller]
119119
fn fail(&self, location: Location, msg: impl AsRef<str>) {
120-
let span = self.body.source_info(location).span;
121-
// We use `span_delayed_bug` as we might see broken MIR when other errors have already
122-
// occurred.
123-
self.tcx.dcx().span_delayed_bug(
124-
span,
125-
format!(
126-
"broken MIR in {:?} ({}) at {:?}:\n{}",
127-
self.body.source.instance,
128-
self.when,
129-
location,
130-
msg.as_ref()
131-
),
120+
// We might see broken MIR when other errors have already occurred.
121+
assert!(
122+
self.tcx.dcx().has_errors().is_some(),
123+
"broken MIR in {:?} ({}) at {:?}:\n{}",
124+
self.body.source.instance,
125+
self.when,
126+
location,
127+
msg.as_ref(),
132128
);
133129
}
134130

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pub(super) fn failed_to_match_macro<'cx>(
3434
if try_success_result.is_ok() {
3535
// Nonterminal parser recovery might turn failed matches into successful ones,
3636
// but for that it must have emitted an error already
37-
tracker
38-
.cx
39-
.dcx()
40-
.span_delayed_bug(sp, "Macro matching returned a success on the second try");
37+
assert!(
38+
tracker.cx.dcx().has_errors().is_some(),
39+
"Macro matching returned a success on the second try"
40+
);
4141
}
4242

4343
if let Some(result) = tracker.result {

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
758758
// since we should have emitten an error for them earlier, and they will
759759
// not be well-formed!
760760
if polarity == ty::ImplPolarity::Negative {
761-
self.tcx().dcx().span_delayed_bug(
762-
binding.span,
761+
assert!(
762+
self.tcx().dcx().has_errors().is_some(),
763763
"negative trait bounds should not have bindings",
764764
);
765765
continue;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,13 +1865,13 @@ fn check_variances_for_type_defn<'tcx>(
18651865
let hir_param = &hir_generics.params[index];
18661866

18671867
if ty_param.def_id != hir_param.def_id.into() {
1868-
// valid programs always have lifetimes before types in the generic parameter list
1868+
// Valid programs always have lifetimes before types in the generic parameter list.
18691869
// ty_generics are normalized to be in this required order, and variances are built
18701870
// from ty generics, not from hir generics. but we need hir generics to get
1871-
// a span out
1871+
// a span out.
18721872
//
1873-
// if they aren't in the same order, then the user has written invalid code, and already
1874-
// got an error about it (or I'm wrong about this)
1873+
// If they aren't in the same order, then the user has written invalid code, and already
1874+
// got an error about it (or I'm wrong about this).
18751875
tcx.dcx().span_delayed_bug(
18761876
hir_param.span,
18771877
"hir generics and ty generics in different order",

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(super) fn check_item(
8585

8686
(_, _, Unsafety::Unsafe, Negative) => {
8787
// Reported in AST validation
88-
tcx.dcx().span_delayed_bug(tcx.def_span(def_id), "unsafe negative impl");
88+
assert!(tcx.dcx().has_errors().is_some(), "unsafe negative impl");
8989
Ok(())
9090
}
9191
(_, _, Unsafety::Normal, Negative)

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139139
| ty::Never
140140
| ty::Dynamic(_, _, ty::DynStar)
141141
| ty::Error(_) => {
142-
let reported = self
142+
let guar = self
143143
.dcx()
144144
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
145-
return Err(reported);
145+
return Err(guar);
146146
}
147147
})
148148
}

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
221221
if base_ty.is_none() {
222222
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
223223
// that isn't in the type table. We assume more relevant errors have already been
224-
// emitted, so we delay an ICE if none have. (#64638)
225-
self.tcx().dcx().span_delayed_bug(e.span, format!("bad base: `{base:?}`"));
224+
// emitted. (#64638)
225+
assert!(self.tcx().dcx().has_errors().is_some(), "bad base: `{base:?}`");
226226
}
227227
if let Some(base_ty) = base_ty
228228
&& let ty::Ref(_, base_ty_inner, _) = *base_ty.kind()

0 commit comments

Comments
 (0)