|
9 | 9 | use std::assert_matches::assert_matches; |
10 | 10 | use std::borrow::Cow; |
11 | 11 | use std::collections::VecDeque; |
12 | | -use std::convert::TryFrom; |
13 | 12 | use std::fmt; |
14 | 13 | use std::ptr; |
15 | 14 |
|
@@ -1172,34 +1171,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { |
1172 | 1171 |
|
1173 | 1172 | /// Machine pointer introspection. |
1174 | 1173 | impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { |
1175 | | - pub fn scalar_to_ptr( |
1176 | | - &self, |
1177 | | - scalar: Scalar<M::Provenance>, |
1178 | | - ) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> { |
1179 | | - // We use `to_bits_or_ptr_internal` since we are just implementing the method people need to |
1180 | | - // call to force getting out a pointer. |
1181 | | - Ok( |
1182 | | - match scalar |
1183 | | - .to_bits_or_ptr_internal(self.pointer_size()) |
1184 | | - .map_err(|s| err_ub!(ScalarSizeMismatch(s)))? |
1185 | | - { |
1186 | | - Err(ptr) => ptr.into(), |
1187 | | - Ok(bits) => { |
1188 | | - let addr = u64::try_from(bits).unwrap(); |
1189 | | - Pointer::from_addr(addr) |
1190 | | - } |
1191 | | - }, |
1192 | | - ) |
1193 | | - } |
1194 | | - |
1195 | 1174 | /// Test if this value might be null. |
1196 | 1175 | /// If the machine does not support ptr-to-int casts, this is conservative. |
1197 | 1176 | pub fn scalar_may_be_null(&self, scalar: Scalar<M::Provenance>) -> InterpResult<'tcx, bool> { |
1198 | 1177 | Ok(match scalar.try_to_int() { |
1199 | 1178 | Ok(int) => int.is_null(), |
1200 | 1179 | Err(_) => { |
1201 | 1180 | // Can only happen during CTFE. |
1202 | | - let ptr = self.scalar_to_ptr(scalar)?; |
| 1181 | + let ptr = scalar.to_pointer(self)?; |
1203 | 1182 | match self.ptr_try_get_alloc_id(ptr) { |
1204 | 1183 | Ok((alloc_id, offset, _)) => { |
1205 | 1184 | let (size, _align, _kind) = self.get_alloc_info(alloc_id); |
|
0 commit comments