Rollup merge of #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`
This commit is contained in:
commit
d5206c6ecd
39 changed files with 130 additions and 155 deletions
|
@ -1237,8 +1237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// trait reference.
|
||||
let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else {
|
||||
// A cycle error occurred, most likely.
|
||||
let guar = tcx.dcx().span_delayed_bug(span, "expected cycle error");
|
||||
return Err(guar);
|
||||
tcx.dcx().span_bug(span, "expected cycle error");
|
||||
};
|
||||
|
||||
self.one_bound_for_assoc_item(
|
||||
|
|
|
@ -257,8 +257,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
fn check_opaque(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
let item = tcx.hir().expect_item(def_id);
|
||||
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
|
||||
tcx.dcx().span_delayed_bug(item.span, "expected opaque item");
|
||||
return;
|
||||
tcx.dcx().span_bug(item.span, "expected opaque item");
|
||||
};
|
||||
|
||||
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
|
||||
|
@ -382,10 +381,10 @@ fn check_opaque_meets_bounds<'tcx>(
|
|||
Ok(()) => {}
|
||||
Err(ty_err) => {
|
||||
let ty_err = ty_err.to_string(tcx);
|
||||
return Err(tcx.dcx().span_delayed_bug(
|
||||
tcx.dcx().span_bug(
|
||||
span,
|
||||
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -734,11 +734,12 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
|
||||
}
|
||||
Err(err) => {
|
||||
let reported = tcx.dcx().span_delayed_bug(
|
||||
return_span,
|
||||
format!("could not fully resolve: {ty} => {err:?}"),
|
||||
);
|
||||
remapped_types.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
|
||||
// This code path is not reached in any tests, but may be
|
||||
// reachable. If this is triggered, it should be converted to
|
||||
// `span_delayed_bug` and the triggering case turned into a
|
||||
// test.
|
||||
tcx.dcx()
|
||||
.span_bug(return_span, format!("could not fully resolve: {ty} => {err:?}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -917,7 +918,13 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
|
|||
.with_note(format!("hidden type inferred to be `{}`", self.ty))
|
||||
.emit()
|
||||
}
|
||||
_ => self.tcx.dcx().delayed_bug("should've been able to remap region"),
|
||||
_ => {
|
||||
// This code path is not reached in any tests, but may be
|
||||
// reachable. If this is triggered, it should be converted
|
||||
// to `delayed_bug` and the triggering case turned into a
|
||||
// test.
|
||||
self.tcx.dcx().bug("should've been able to remap region");
|
||||
}
|
||||
};
|
||||
return Err(guar);
|
||||
};
|
||||
|
@ -1276,9 +1283,10 @@ fn compare_number_of_generics<'tcx>(
|
|||
// inheriting the generics from will also have mismatched arguments, and
|
||||
// we'll report an error for that instead. Delay a bug for safety, though.
|
||||
if trait_.is_impl_trait_in_trait() {
|
||||
return Err(tcx.dcx().delayed_bug(
|
||||
"errors comparing numbers of generics of trait/impl functions were not emitted",
|
||||
));
|
||||
// FIXME: no tests trigger this. If you find example code that does
|
||||
// trigger this, please add it to the test suite.
|
||||
tcx.dcx()
|
||||
.bug("errors comparing numbers of generics of trait/impl functions were not emitted");
|
||||
}
|
||||
|
||||
let matchings = [
|
||||
|
|
|
@ -154,8 +154,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
|
|||
trait_m_sig.inputs_and_output,
|
||||
));
|
||||
if !ocx.select_all_or_error().is_empty() {
|
||||
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
|
||||
return;
|
||||
// This code path is not reached in any tests, but may be reachable. If
|
||||
// this is triggered, it should be converted to `delayed_bug` and the
|
||||
// triggering case turned into a test.
|
||||
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
|
||||
}
|
||||
let outlives_env = OutlivesEnvironment::with_bounds(
|
||||
param_env,
|
||||
|
@ -163,13 +165,17 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
|
|||
);
|
||||
let errors = infcx.resolve_regions(&outlives_env);
|
||||
if !errors.is_empty() {
|
||||
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
|
||||
return;
|
||||
// This code path is not reached in any tests, but may be reachable. If
|
||||
// this is triggered, it should be converted to `delayed_bug` and the
|
||||
// triggering case turned into a test.
|
||||
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
|
||||
}
|
||||
// Resolve any lifetime variables that may have been introduced during normalization.
|
||||
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
|
||||
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
|
||||
return;
|
||||
// This code path is not reached in any tests, but may be reachable. If
|
||||
// this is triggered, it should be converted to `delayed_bug` and the
|
||||
// triggering case turned into a test.
|
||||
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
|
||||
};
|
||||
|
||||
// For quicker lookup, use an `IndexSet` (we don't use one earlier because
|
||||
|
|
|
@ -1087,14 +1087,8 @@ fn check_type_defn<'tcx>(
|
|||
packed && {
|
||||
let ty = tcx.type_of(variant.tail().did).instantiate_identity();
|
||||
let ty = tcx.erase_regions(ty);
|
||||
if ty.has_infer() {
|
||||
tcx.dcx()
|
||||
.span_delayed_bug(item.span, format!("inference variables in {ty:?}"));
|
||||
// Just treat unresolved type expression as if it needs drop.
|
||||
true
|
||||
} else {
|
||||
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
|
||||
}
|
||||
assert!(!ty.has_infer());
|
||||
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
|
||||
}
|
||||
};
|
||||
// All fields (except for possibly the last) should be sized.
|
||||
|
|
|
@ -315,7 +315,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
|||
|
||||
if is_host_effect {
|
||||
if let Some(idx) = host_effect_index {
|
||||
tcx.dcx().span_delayed_bug(
|
||||
tcx.dcx().span_bug(
|
||||
param.span,
|
||||
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"),
|
||||
);
|
||||
|
|
|
@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
self.tcx.dcx().span_delayed_bug(
|
||||
self.tcx.dcx().span_bug(
|
||||
lifetime_ref.ident.span,
|
||||
format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
|
||||
);
|
||||
|
@ -1465,10 +1465,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
self.tcx.dcx().span_delayed_bug(
|
||||
self.tcx.hir().span(hir_id),
|
||||
format!("could not resolve {param_def_id:?}"),
|
||||
);
|
||||
self.tcx
|
||||
.dcx()
|
||||
.span_bug(self.tcx.hir().span(hir_id), format!("could not resolve {param_def_id:?}"));
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue