Skip to content

Commit fb9b693

Browse files
committed
Miri engine: use span_bug in a few places
1 parent 0ad3b1c commit fb9b693

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

src/librustc_mir/interpret/eval_context.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
256256
/// or compute the layout.
257257
#[cfg_attr(not(debug_assertions), inline(always))]
258258
pub(super) fn from_known_layout<'tcx>(
259-
tcx: TyCtxt<'tcx>,
259+
tcx: TyCtxtAt<'tcx>,
260260
known_layout: Option<TyAndLayout<'tcx>>,
261261
compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
262262
) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
@@ -265,12 +265,14 @@ pub(super) fn from_known_layout<'tcx>(
265265
Some(known_layout) => {
266266
if cfg!(debug_assertions) {
267267
let check_layout = compute()?;
268-
assert!(
269-
mir_assign_valid_types(tcx, check_layout, known_layout),
270-
"expected type differs from actual type.\nexpected: {:?}\nactual: {:?}",
271-
known_layout.ty,
272-
check_layout.ty,
273-
);
268+
if !mir_assign_valid_types(tcx.tcx, check_layout, known_layout) {
269+
span_bug!(
270+
tcx.span,
271+
"expected type differs from actual type.\nexpected: {:?}\nactual: {:?}",
272+
known_layout.ty,
273+
check_layout.ty,
274+
);
275+
}
274276
}
275277
Ok(known_layout)
276278
}
@@ -444,7 +446,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
444446
// have to support that case (mostly by skipping all caching).
445447
match frame.locals.get(local).and_then(|state| state.layout.get()) {
446448
None => {
447-
let layout = from_known_layout(self.tcx.tcx, layout, || {
449+
let layout = from_known_layout(self.tcx, layout, || {
448450
let local_ty = frame.body.local_decls[local].ty;
449451
let local_ty =
450452
self.subst_from_frame_and_normalize_erasing_regions(frame, local_ty);

src/librustc_mir/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
529529
ty::ConstKind::Value(val_val) => val_val,
530530
};
531531
// Other cases need layout.
532-
let layout = from_known_layout(self.tcx.tcx, layout, || self.layout_of(val.ty))?;
532+
let layout = from_known_layout(self.tcx, layout, || self.layout_of(val.ty))?;
533533
let op = match val_val {
534534
ConstValue::ByRef { alloc, offset } => {
535535
let id = self.tcx.alloc_map.lock().create_memory_alloc(alloc);

src/librustc_mir/interpret/place.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,14 @@ where
867867
) -> InterpResult<'tcx> {
868868
// We do NOT compare the types for equality, because well-typed code can
869869
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
870-
assert!(
871-
mir_assign_valid_types(self.tcx.tcx, src.layout, dest.layout),
872-
"type mismatch when copying!\nsrc: {:?},\ndest: {:?}",
873-
src.layout.ty,
874-
dest.layout.ty,
875-
);
870+
if !mir_assign_valid_types(self.tcx.tcx, src.layout, dest.layout) {
871+
span_bug!(
872+
self.tcx.span,
873+
"type mismatch when copying!\nsrc: {:?},\ndest: {:?}",
874+
src.layout.ty,
875+
dest.layout.ty,
876+
);
877+
}
876878

877879
// Let us see if the layout is simple so we take a shortcut, avoid force_allocation.
878880
let src = match self.try_read_immediate(src)? {

src/librustc_mir/interpret/terminator.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6666
let sig = func.layout.ty.fn_sig(*self.tcx);
6767
(FnVal::Instance(self.resolve(def_id, substs)?), sig.abi())
6868
}
69-
_ => bug!("invalid callee of type {:?}", func.layout.ty),
69+
_ => span_bug!(
70+
terminator.source_info.span,
71+
"invalid callee of type {:?}",
72+
func.layout.ty
73+
),
7074
};
7175
let args = self.eval_operands(args)?;
7276
let ret = match destination {
@@ -76,7 +80,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7680
self.eval_fn_call(fn_val, abi, &args[..], ret, *cleanup)?;
7781
// Sanity-check that `eval_fn_call` either pushed a new frame or
7882
// did a jump to another block.
79-
assert!(self.cur_frame() != old_stack || self.frame().block != old_bb);
83+
if self.cur_frame() == old_stack && self.frame().block == old_bb {
84+
span_bug!(terminator.source_info.span, "evaluating this call made no progress");
85+
}
8086
}
8187

8288
Drop { location, target, unwind } => {
@@ -121,9 +127,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
121127
| FalseEdges { .. }
122128
| FalseUnwind { .. }
123129
| Yield { .. }
124-
| GeneratorDrop => {
125-
bug!("{:#?} should have been eliminated by MIR pass", terminator.kind)
126-
}
130+
| GeneratorDrop => span_bug!(
131+
terminator.source_info.span,
132+
"{:#?} should have been eliminated by MIR pass",
133+
terminator.kind
134+
),
127135
}
128136

129137
Ok(())

0 commit comments

Comments
 (0)