Skip to content

Commit 81794be

Browse files
authored
Rollup merge of rust-lang#94271 - RalfJung:downcast, r=oli-obk
Miri: extend comments on downcast operation r? `@oli-obk`
2 parents efe6a97 + d0192e6 commit 81794be

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
405405
op: &OpTy<'tcx, M::PointerTag>,
406406
variant: VariantIdx,
407407
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
408-
// Downcasts only change the layout
409408
Ok(match op.try_as_mplace() {
410409
Ok(ref mplace) => self.mplace_downcast(mplace, variant)?.into(),
411410
Err(..) => {
411+
// Downcasts only change the layout.
412+
// (In particular, no check about whether this is even the active variant -- that's by design,
413+
// see https://github.com/rust-lang/rust/issues/93688#issuecomment-1032929496.)
412414
let layout = op.layout.for_variant(self, variant);
413415
OpTy { layout, ..*op }
414416
}

compiler/rustc_const_eval/src/interpret/place.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,9 @@ where
479479
base: &MPlaceTy<'tcx, M::PointerTag>,
480480
variant: VariantIdx,
481481
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
482-
// Downcasts only change the layout
482+
// Downcasts only change the layout.
483+
// (In particular, no check about whether this is even the active variant -- that's by design,
484+
// see https://github.com/rust-lang/rust/issues/93688#issuecomment-1032929496.)
483485
assert!(!base.meta.has_meta());
484486
Ok(MPlaceTy { layout: base.layout.for_variant(self, variant), ..*base })
485487
}

0 commit comments

Comments
 (0)