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

Commit d5206c6

Browse files
authored
Rollup merge of rust-lang#121208 - nnethercote:delayed_bug-to-bug, r=lcnr
Convert `delayed_bug`s to `bug`s. I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. This is too dangerous to merge. Increased coverage (fuzzing or a crater run) would likely hit more cases. But it might be useful for people to look at and think about which paths are genuinely unreachable. r? `@ghost`
2 parents 0987e41 + 2903bbb commit d5206c6

File tree

39 files changed

+130
-155
lines changed

39 files changed

+130
-155
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,9 +1636,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16361636
if let Some(old_def_id) = self.orig_opt_local_def_id(param) {
16371637
old_def_id
16381638
} else {
1639-
self.dcx()
1640-
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1641-
continue;
1639+
self.dcx().span_bug(lifetime.ident.span, "no def-id for fresh lifetime");
16421640
}
16431641
}
16441642

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
626626
| GenericArgKind::Const(_),
627627
_,
628628
) => {
629-
// 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(
629+
// This was previously a `span_delayed_bug` and could be
630+
// reached by the test for #82126, but no longer.
631+
self.dcx().span_bug(
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
316316
.and(type_op::normalize::Normalize::new(ty))
317317
.fully_perform(self.infcx, span)
318318
else {
319+
// Note: this path is currently not reached in any test, so
320+
// any example that triggers this would be worth minimizing
321+
// and converting into a test.
319322
tcx.dcx().span_delayed_bug(span, format!("failed to normalize {ty:?}"));
320323
continue;
321324
};

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
154154
if argument_index + 1 >= body.local_decls.len() {
155155
self.tcx()
156156
.dcx()
157-
.span_delayed_bug(body.span, "found more normalized_input_ty than local_decls");
158-
break;
157+
.span_bug(body.span, "found more normalized_input_ty than local_decls");
159158
}
160159

161160
// In MIR, argument N is stored in local N+1.

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,13 @@ pub(crate) fn type_check<'mir, 'tcx>(
220220
"opaque_type_map",
221221
),
222222
);
223-
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
223+
let hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
224224
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
225225
if hidden_type.has_non_region_infer() {
226-
let reported = infcx.dcx().span_delayed_bug(
226+
infcx.dcx().span_bug(
227227
decl.hidden_type.span,
228228
format!("could not resolve {:#?}", hidden_type.ty.kind()),
229229
);
230-
hidden_type.ty = Ty::new_error(infcx.tcx, reported);
231230
}
232231

233232
(opaque_type_key, hidden_type)
@@ -1089,10 +1088,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10891088
);
10901089

10911090
if result.is_err() {
1092-
self.infcx.dcx().span_delayed_bug(
1093-
self.body.span,
1094-
"failed re-defining predefined opaques in mir typeck",
1095-
);
1091+
self.infcx
1092+
.dcx()
1093+
.span_bug(self.body.span, "failed re-defining predefined opaques in mir typeck");
10961094
}
10971095
}
10981096

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
393393
if ecx.tcx.is_ctfe_mir_available(def) {
394394
Ok(ecx.tcx.mir_for_ctfe(def))
395395
} else if ecx.tcx.def_kind(def) == DefKind::AssocConst {
396-
let guar = ecx
397-
.tcx
398-
.dcx()
399-
.delayed_bug("This is likely a const item that is missing from its impl");
400-
throw_inval!(AlreadyReported(guar.into()));
396+
ecx.tcx.dcx().bug("This is likely a const item that is missing from its impl");
401397
} else {
402398
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
403399
// so this should be unreachable.

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
329329

330330
fn check_static(&mut self, def_id: DefId, span: Span) {
331331
if self.tcx.is_thread_local_static(def_id) {
332-
self.tcx
333-
.dcx()
334-
.span_delayed_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
332+
self.tcx.dcx().span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
335333
}
336334
self.check_op_spanned(ops::StaticAccess, span)
337335
}

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
517517

518518
fn visit_source_scope(&mut self, scope: SourceScope) {
519519
if self.body.source_scopes.get(scope).is_none() {
520-
self.tcx.dcx().span_delayed_bug(
520+
self.tcx.dcx().span_bug(
521521
self.body.span,
522522
format!(
523523
"broken MIR in {:?} ({}):\ninvalid source scope {:?}",

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12371237
// trait reference.
12381238
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
12391239
// A cycle error occurred, most likely.
1240-
let guar = tcx.dcx().span_delayed_bug(span, "expected cycle error");
1241-
return Err(guar);
1240+
tcx.dcx().span_bug(span, "expected cycle error");
12421241
};
12431242

12441243
self.one_bound_for_assoc_item(

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
257257
fn check_opaque(tcx: TyCtxt<'_>, def_id: LocalDefId) {
258258
let item = tcx.hir().expect_item(def_id);
259259
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
260-
tcx.dcx().span_delayed_bug(item.span, "expected opaque item");
261-
return;
260+
tcx.dcx().span_bug(item.span, "expected opaque item");
262261
};
263262

264263
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
@@ -382,10 +381,10 @@ fn check_opaque_meets_bounds<'tcx>(
382381
Ok(()) => {}
383382
Err(ty_err) => {
384383
let ty_err = ty_err.to_string(tcx);
385-
return Err(tcx.dcx().span_delayed_bug(
384+
tcx.dcx().span_bug(
386385
span,
387386
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
388-
));
387+
);
389388
}
390389
}
391390

0 commit comments

Comments
 (0)