Skip to content

Commit 8298c84

Browse files
committed
Make unreachable path trigger ICE with span
1 parent 852c332 commit 8298c84

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::interpret::{read_target_uint, write_target_uint};
1111
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
1212
use rustc_middle::ty::layout::TyAndLayout;
1313
use rustc_middle::ty::{Ty, TyCtxt, Upcast};
14-
use rustc_middle::{bug, ty};
14+
use rustc_middle::{bug, span_bug, ty};
1515
use rustc_span::{Symbol, sym};
1616
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
1717
use tracing::trace;
@@ -21,7 +21,7 @@ use super::util::ensure_monomorphic_enough;
2121
use super::{
2222
Allocation, CheckInAllocMsg, ConstAllocation, ImmTy, InterpCx, InterpResult, Machine, OpTy,
2323
PlaceTy, Pointer, PointerArithmetic, Provenance, Scalar, err_ub_custom, err_unsup_format,
24-
interp_ok, throw_inval, throw_ub_custom, throw_ub_format, throw_unsup_format,
24+
interp_ok, throw_inval, throw_ub_custom, throw_ub_format,
2525
};
2626
use crate::fluent_generated as fluent;
2727

@@ -156,17 +156,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
156156

157157
ensure_monomorphic_enough(tcx, tp_ty)?;
158158
ensure_monomorphic_enough(tcx, result_ty)?;
159-
160159
let ty::Dynamic(preds, _, ty::Dyn) = result_ty.kind() else {
161-
throw_unsup_format!(
160+
span_bug!(
161+
self.find_closest_untracked_caller_location(),
162162
"Invalid type provided to vtable_for::<T, U>. U must be dyn Trait, got {result_ty}."
163163
);
164164
};
165165

166-
let (infcx, param_env) = self
167-
.tcx
168-
.infer_ctxt()
169-
.build_with_typing_env(self.typing_env);
166+
let (infcx, param_env) =
167+
self.tcx.infer_ctxt().build_with_typing_env(self.typing_env);
170168

171169
let type_impls_trait = preds.iter().all(|pred| {
172170
let trait_ref = ty::TraitRef::new(tcx, pred.def_id(), [tp_ty]);

0 commit comments

Comments
 (0)