diff options
| author | Ralf Jung <post@ralfj.de> | 2022-07-24 14:04:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-24 14:04:26 -0400 |
| commit | 890cd7a496b8002debead4b970bd2f24dcb9c014 (patch) | |
| tree | 1bc9dbdce55f7c08204622e3c6f9bb9ed167426a /compiler/rustc_const_eval/src/interpret/memory.rs | |
| parent | c32dcbba187d1ee0dbe92dc152cb9c2f3f42900c (diff) | |
| parent | 4e89a7c29325964182e0fb9f92539cf2d9f18e82 (diff) | |
| download | rust-890cd7a496b8002debead4b970bd2f24dcb9c014.tar.gz rust-890cd7a496b8002debead4b970bd2f24dcb9c014.zip | |
Rollup merge of #99644 - RalfJung:interpret-int-ptr-transmute, r=oli-obk
remove some provenance-related machine hooks that Miri no longer needs Then we can make `scalar_to_ptr` a method on `Scalar`. :) Fixes https://github.com/rust-lang/miri/issues/2188 r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/memory.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 86914f50383..ed2c4edf9dd 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -9,7 +9,6 @@ use std::assert_matches::assert_matches; use std::borrow::Cow; use std::collections::VecDeque; -use std::convert::TryFrom; use std::fmt; use std::ptr; @@ -1172,26 +1171,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// Machine pointer introspection. impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { - pub fn scalar_to_ptr( - &self, - scalar: Scalar<M::Provenance>, - ) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> { - // We use `to_bits_or_ptr_internal` since we are just implementing the method people need to - // call to force getting out a pointer. - Ok( - match scalar - .to_bits_or_ptr_internal(self.pointer_size()) - .map_err(|s| err_ub!(ScalarSizeMismatch(s)))? - { - Err(ptr) => ptr.into(), - Ok(bits) => { - let addr = u64::try_from(bits).unwrap(); - M::ptr_from_addr_transmute(&self, addr) - } - }, - ) - } - /// Test if this value might be null. /// If the machine does not support ptr-to-int casts, this is conservative. pub fn scalar_may_be_null(&self, scalar: Scalar<M::Provenance>) -> InterpResult<'tcx, bool> { @@ -1199,7 +1178,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Ok(int) => int.is_null(), Err(_) => { // Can only happen during CTFE. - let ptr = self.scalar_to_ptr(scalar)?; + let ptr = scalar.to_pointer(self)?; match self.ptr_try_get_alloc_id(ptr) { Ok((alloc_id, offset, _)) => { let (size, _align, _kind) = self.get_alloc_info(alloc_id); |
