diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-08-19 12:26:41 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-19 12:26:41 +0530 |
| commit | c4707ff8ef8b1a8810afd3fbca91043600b934a0 (patch) | |
| tree | 0c68719478fcea3414cbeb72884d72ce43b3acbc /compiler/rustc_const_eval/src | |
| parent | 2fe29753912a1be758a56453eaa80ddbe745300a (diff) | |
| parent | 3c8563abcf91eda340aa77d238954dd00fa0cb34 (diff) | |
| download | rust-c4707ff8ef8b1a8810afd3fbca91043600b934a0.tar.gz rust-c4707ff8ef8b1a8810afd3fbca91043600b934a0.zip | |
Rollup merge of #100208 - RalfJung:dyn-upcast-nop, r=petrochenkov
make NOP dyn casts not require anything about the vtable As suggested [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/dyn-upcasting.20stabilization/near/292151439). This matches what the codegen backends already do, and what Miri did do until https://github.com/rust-lang/rust/pull/99420 when I made it super extra paranoid.
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/cast.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index c97c31eb9da..14eb2a1537b 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -298,7 +298,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.write_immediate(val, dest) } (&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => { - let (old_data, old_vptr) = self.read_immediate(src)?.to_scalar_pair()?; + let val = self.read_immediate(src)?; + if data_a.principal() == data_b.principal() { + // A NOP cast that doesn't actually change anything, should be allowed even with mismatching vtables. + return self.write_immediate(*val, dest); + } + let (old_data, old_vptr) = val.to_scalar_pair()?; let old_vptr = old_vptr.to_pointer(self)?; let (ty, old_trait) = self.get_ptr_vtable(old_vptr)?; if old_trait != data_a.principal() { |
