Skip to content

Commit 2903bbb

Browse files
committed
Convert bugs back to delayed_bugs.
This commit undoes some of the previous commit's mechanical changes, based on human judgment.
1 parent 010f394 commit 2903bbb

File tree

24 files changed

+87
-42
lines changed

24 files changed

+87
-42
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ 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.
629+
// This was previously a `span_delayed_bug` and could be
630+
// reached by the test for #82126, but no longer.
631631
self.dcx().span_bug(
632632
hir_arg.span(),
633633
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
316316
.and(type_op::normalize::Normalize::new(ty))
317317
.fully_perform(self.infcx, span)
318318
else {
319-
tcx.dcx().span_bug(span, format!("failed to normalize {ty:?}"));
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.
322+
tcx.dcx().span_delayed_bug(span, format!("failed to normalize {ty:?}"));
323+
continue;
320324
};
321325
constraints.extend(c);
322326

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
622622
);
623623
// If this was a hard error, don't bother continuing evaluation.
624624
if is_error {
625-
let guard: rustc_errors::ErrorGuaranteed = ecx
625+
let guard = ecx
626626
.tcx
627627
.dcx()
628628
.span_delayed_bug(span, "The deny lint should have already errored");

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,10 @@ 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+
// This code path is not reached in any tests, but may be
738+
// reachable. If this is triggered, it should be converted to
739+
// `span_delayed_bug` and the triggering case turned into a
740+
// test.
737741
tcx.dcx()
738742
.span_bug(return_span, format!("could not fully resolve: {ty} => {err:?}"));
739743
}
@@ -914,7 +918,13 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
914918
.with_note(format!("hidden type inferred to be `{}`", self.ty))
915919
.emit()
916920
}
917-
_ => self.tcx.dcx().bug("should've been able to remap region"),
921+
_ => {
922+
// This code path is not reached in any tests, but may be
923+
// reachable. If this is triggered, it should be converted
924+
// to `delayed_bug` and the triggering case turned into a
925+
// test.
926+
self.tcx.dcx().bug("should've been able to remap region");
927+
}
918928
};
919929
return Err(guar);
920930
};
@@ -1273,6 +1283,8 @@ fn compare_number_of_generics<'tcx>(
12731283
// inheriting the generics from will also have mismatched arguments, and
12741284
// we'll report an error for that instead. Delay a bug for safety, though.
12751285
if trait_.is_impl_trait_in_trait() {
1286+
// FIXME: no tests trigger this. If you find example code that does
1287+
// trigger this, please add it to the test suite.
12761288
tcx.dcx()
12771289
.bug("errors comparing numbers of generics of trait/impl functions were not emitted");
12781290
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ 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+
// This code path is not reached in any tests, but may be reachable. If
158+
// this is triggered, it should be converted to `delayed_bug` and the
159+
// triggering case turned into a test.
157160
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
158161
}
159162
let outlives_env = OutlivesEnvironment::with_bounds(
@@ -162,10 +165,16 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
162165
);
163166
let errors = infcx.resolve_regions(&outlives_env);
164167
if !errors.is_empty() {
168+
// This code path is not reached in any tests, but may be reachable. If
169+
// this is triggered, it should be converted to `delayed_bug` and the
170+
// triggering case turned into a test.
165171
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
166172
}
167173
// Resolve any lifetime variables that may have been introduced during normalization.
168174
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
175+
// This code path is not reached in any tests, but may be reachable. If
176+
// this is triggered, it should be converted to `delayed_bug` and the
177+
// triggering case turned into a test.
169178
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
170179
};
171180

compiler/rustc_hir_analysis/src/check/dropck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ 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-
tcx.dcx().span_bug(
70+
let reported = tcx.dcx().span_delayed_bug(
7171
span,
7272
format!("should have been rejected by coherence check: {dtor_self_type}"),
7373
);
74+
Err(reported)
7475
}
7576
}
7677
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,8 @@ fn check_type_defn<'tcx>(
10871087
packed && {
10881088
let ty = tcx.type_of(variant.tail().did).instantiate_identity();
10891089
let ty = tcx.erase_regions(ty);
1090-
if ty.has_infer() {
1091-
// Unresolved type expression.
1092-
tcx.dcx().span_bug(item.span, format!("inference variables in {ty:?}"));
1093-
} else {
1094-
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
1095-
}
1090+
assert!(!ty.has_infer());
1091+
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
10961092
}
10971093
};
10981094
// All fields (except for possibly the last) should be sized.

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,9 +1315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13151315
// the LUB of the breaks (possibly ! if none); else, it
13161316
// is nil. This makes sense because infinite loops
13171317
// (which would have type !) are only possible iff we
1318-
// permit break with a value [1].
1318+
// permit break with a value.
13191319
if ctxt.coerce.is_none() && !ctxt.may_break {
1320-
// [1]
13211320
self.dcx().span_bug(body.span, "no coercion, but loop may not break");
13221321
}
13231322
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| Ty::new_unit(self.tcx))

compiler/rustc_hir_typeck/src/intrinsicck.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ 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+
// Note: this path is currently not reached in any test, so any
52+
// example that triggers this would be worth minimizing and
53+
// converting into a test.
5154
tcx.dcx().span_bug(span, "argument to transmute has inference variables");
5255
}
5356
// Transmutes that are only changing lifetimes are always ok.

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
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_bug(
927+
tcx.dcx().span_delayed_bug(
928928
*item_span,
929929
"auto trait is invoked with no method error, but no error reported?",
930930
);

0 commit comments

Comments
 (0)