Skip to content

Commit 010f394

Browse files
committed
Convert delayed_bugs to bugs.
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. The next commit will convert some more back, based on human judgment.
1 parent bb59453 commit 010f394

File tree

44 files changed

+87
-157
lines changed

Some content is hidden

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

44 files changed

+87
-157
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-3
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
628628
) => {
629629
// HIR lowering sometimes doesn't catch this in erroneous
630630
// programs, so we need to use span_delayed_bug here. See #82126.
631-
self.dcx().span_delayed_bug(
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +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:?}"));
320-
continue;
319+
tcx.dcx().span_bug(span, format!("failed to normalize {ty:?}"));
321320
};
322321
constraints.extend(c);
323322

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-2
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

+5-7
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

+2-6
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.
@@ -626,7 +622,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
626622
);
627623
// If this was a hard error, don't bother continuing evaluation.
628624
if is_error {
629-
let guard = ecx
625+
let guard: rustc_errors::ErrorGuaranteed = ecx
630626
.tcx
631627
.dcx()
632628
.span_delayed_bug(span, "The deny lint should have already errored");

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

+1-3
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

+1-1
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

+1-2
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

+3-4
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

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,8 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
734734
remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
735735
}
736736
Err(err) => {
737-
let reported = tcx.dcx().span_delayed_bug(
738-
return_span,
739-
format!("could not fully resolve: {ty} => {err:?}"),
740-
);
741-
remapped_types.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
737+
tcx.dcx()
738+
.span_bug(return_span, format!("could not fully resolve: {ty} => {err:?}"));
742739
}
743740
}
744741
}
@@ -917,7 +914,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
917914
.with_note(format!("hidden type inferred to be `{}`", self.ty))
918915
.emit()
919916
}
920-
_ => self.tcx.dcx().delayed_bug("should've been able to remap region"),
917+
_ => self.tcx.dcx().bug("should've been able to remap region"),
921918
};
922919
return Err(guar);
923920
};
@@ -1276,9 +1273,8 @@ fn compare_number_of_generics<'tcx>(
12761273
// inheriting the generics from will also have mismatched arguments, and
12771274
// we'll report an error for that instead. Delay a bug for safety, though.
12781275
if trait_.is_impl_trait_in_trait() {
1279-
return Err(tcx.dcx().delayed_bug(
1280-
"errors comparing numbers of generics of trait/impl functions were not emitted",
1281-
));
1276+
tcx.dcx()
1277+
.bug("errors comparing numbers of generics of trait/impl functions were not emitted");
12821278
}
12831279

12841280
let matchings = [

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,19 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
154154
trait_m_sig.inputs_and_output,
155155
));
156156
if !ocx.select_all_or_error().is_empty() {
157-
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
158-
return;
157+
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
159158
}
160159
let outlives_env = OutlivesEnvironment::with_bounds(
161160
param_env,
162161
infcx.implied_bounds_tys(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
163162
);
164163
let errors = infcx.resolve_regions(&outlives_env);
165164
if !errors.is_empty() {
166-
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
167-
return;
165+
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
168166
}
169167
// Resolve any lifetime variables that may have been introduced during normalization.
170168
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
171-
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
172-
return;
169+
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
173170
};
174171

175172
// For quicker lookup, use an `IndexSet` (we don't use one earlier because

compiler/rustc_hir_analysis/src/check/dropck.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), Erro
6767
// already checked by coherence, but compilation may
6868
// not have been terminated.
6969
let span = tcx.def_span(drop_impl_did);
70-
let reported = tcx.dcx().span_delayed_bug(
70+
tcx.dcx().span_bug(
7171
span,
7272
format!("should have been rejected by coherence check: {dtor_self_type}"),
7373
);
74-
Err(reported)
7574
}
7675
}
7776
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,8 @@ fn check_type_defn<'tcx>(
10881088
let ty = tcx.type_of(variant.tail().did).instantiate_identity();
10891089
let ty = tcx.erase_regions(ty);
10901090
if ty.has_infer() {
1091-
tcx.dcx()
1092-
.span_delayed_bug(item.span, format!("inference variables in {ty:?}"));
1093-
// Just treat unresolved type expression as if it needs drop.
1094-
true
1091+
// Unresolved type expression.
1092+
tcx.dcx().span_bug(item.span, format!("inference variables in {ty:?}"));
10951093
} else {
10961094
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
10971095
}

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
315315

316316
if is_host_effect {
317317
if let Some(idx) = host_effect_index {
318-
tcx.dcx().span_delayed_bug(
318+
tcx.dcx().span_bug(
319319
param.span,
320320
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"),
321321
);

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13311331
}
13321332
}
13331333

1334-
self.tcx.dcx().span_delayed_bug(
1334+
self.tcx.dcx().span_bug(
13351335
lifetime_ref.ident.span,
13361336
format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
13371337
);
@@ -1465,10 +1465,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14651465
}
14661466
}
14671467

1468-
self.tcx.dcx().span_delayed_bug(
1469-
self.tcx.hir().span(hir_id),
1470-
format!("could not resolve {param_def_id:?}"),
1471-
);
1468+
self.tcx
1469+
.dcx()
1470+
.span_bug(self.tcx.hir().span(hir_id), format!("could not resolve {param_def_id:?}"));
14721471
}
14731472

14741473
#[instrument(level = "debug", skip(self))]

compiler/rustc_hir_typeck/src/cast.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139139
| ty::Never
140140
| ty::Dynamic(_, _, ty::DynStar)
141141
| ty::Error(_) => {
142-
let guar = self
143-
.dcx()
144-
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
145-
return Err(guar);
142+
self.dcx().span_bug(span, format!("`{t:?}` should be sized but is not?"));
146143
}
147144
})
148145
}

compiler/rustc_hir_typeck/src/expr.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7676
// While we don't allow *arbitrary* coercions here, we *do* allow
7777
// coercions from ! to `expected`.
7878
if ty.is_never() {
79-
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
80-
let reported = self.dcx().span_delayed_bug(
81-
expr.span,
82-
"expression with never type wound up being adjusted",
83-
);
84-
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
85-
target.to_owned()
86-
} else {
87-
Ty::new_error(self.tcx(), reported)
88-
};
79+
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
80+
self.dcx()
81+
.span_bug(expr.span, "expression with never type wound up being adjusted");
8982
}
9083

9184
let adj_ty = self.next_ty_var(TypeVariableOrigin {
@@ -1325,7 +1318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13251318
// permit break with a value [1].
13261319
if ctxt.coerce.is_none() && !ctxt.may_break {
13271320
// [1]
1328-
self.dcx().span_delayed_bug(body.span, "no coercion, but loop may not break");
1321+
self.dcx().span_bug(body.span, "no coercion, but loop may not break");
13291322
}
13301323
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| Ty::new_unit(self.tcx))
13311324
}

compiler/rustc_hir_typeck/src/intrinsicck.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4848
let to = normalize(to);
4949
trace!(?from, ?to);
5050
if from.has_non_region_infer() || to.has_non_region_infer() {
51-
tcx.dcx().span_delayed_bug(span, "argument to transmute has inference variables");
52-
return;
51+
tcx.dcx().span_bug(span, "argument to transmute has inference variables");
5352
}
5453
// Transmutes that are only changing lifetimes are always ok.
5554
if from == to {

compiler/rustc_hir_typeck/src/mem_categorization.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
570570
_ => {
571571
self.tcx()
572572
.dcx()
573-
.span_delayed_bug(span, "struct or tuple struct pattern not applied to an ADT");
574-
Err(())
573+
.span_bug(span, "struct or tuple struct pattern not applied to an ADT");
575574
}
576575
}
577576
}
@@ -583,8 +582,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
583582
match ty.kind() {
584583
ty::Tuple(args) => Ok(args.len()),
585584
_ => {
586-
self.tcx().dcx().span_delayed_bug(span, "tuple pattern not applied to a tuple");
587-
Err(())
585+
self.tcx().dcx().span_bug(span, "tuple pattern not applied to a tuple");
588586
}
589587
}
590588
}

compiler/rustc_hir_typeck/src/method/probe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
804804
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
805805
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
806806
if new_trait_ref.has_non_region_bound_vars() {
807-
this.dcx().span_delayed_bug(
807+
this.dcx().span_bug(
808808
this.span,
809809
"tried to select method from HRTB with non-lifetime bound vars",
810810
);
811-
return;
812811
}
813812

814813
let new_trait_ref = this.instantiate_bound_regions_with_erased(new_trait_ref);

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
924924
span: item_span,
925925
..
926926
})) => {
927-
tcx.dcx().span_delayed_bug(
927+
tcx.dcx().span_bug(
928928
*item_span,
929929
"auto trait is invoked with no method error, but no error reported?",
930930
);

compiler/rustc_hir_typeck/src/pat.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10851085

10861086
let variant = match res {
10871087
Res::Err => {
1088-
let e = tcx.dcx().span_delayed_bug(pat.span, "`Res::Err` but no error emitted");
1089-
self.set_tainted_by_errors(e);
1090-
on_error(e);
1091-
return Ty::new_error(tcx, e);
1088+
tcx.dcx().span_bug(pat.span, "`Res::Err` but no error emitted");
10921089
}
10931090
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => {
10941091
let e = report_unexpected_res(res);

compiler/rustc_infer/src/infer/outlives/obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ where
303303
// Ignore this, we presume it will yield an error later,
304304
// since if a type variable is not resolved by this point
305305
// it never will be.
306-
self.tcx.dcx().span_delayed_bug(
306+
self.tcx.dcx().span_bug(
307307
origin.span(),
308308
format!("unresolved inference variable in outlives: {v:?}"),
309309
);

compiler/rustc_infer/src/infer/outlives/verify.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
175175
// Ignore this, we presume it will yield an error later, since
176176
// if a type variable is not resolved by this point it never
177177
// will be.
178-
self.tcx
179-
.dcx()
180-
.delayed_bug(format!("unresolved inference variable in outlives: {v:?}"));
181-
// Add a bound that never holds.
182-
VerifyBound::AnyBound(vec![])
178+
self.tcx.dcx().bug(format!("unresolved inference variable in outlives: {v:?}"));
183179
}
184180
}
185181
}

0 commit comments

Comments
 (0)