add is_any_ptr type test; this also helps pacify tidy

This commit is contained in:
Ralf Jung 2019-07-25 01:02:41 +02:00
parent 144e5e99b5
commit 7b30612c9b
4 changed files with 9 additions and 6 deletions

View file

@ -1863,6 +1863,12 @@ impl<'tcx> TyS<'tcx> {
}
}
/// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
#[inline]
pub fn is_any_ptr(&self) -> bool {
self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr()
}
/// Returns `true` if this type is an `Arc<T>`.
#[inline]
pub fn is_arc(&self) -> bool {

View file

@ -105,8 +105,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
assert!(
src.layout.ty.is_bool() || src.layout.ty.is_char() ||
src.layout.ty.is_enum() || src.layout.ty.is_integral() ||
src.layout.ty.is_unsafe_ptr() || src.layout.ty.is_fn_ptr() ||
src.layout.ty.is_region_ptr(),
src.layout.ty.is_any_ptr(),
"Unexpected cast from type {:?}", src.layout.ty
)
}
@ -143,8 +142,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
// Handle casting any ptr to raw ptr (might be a fat ptr).
if (src.layout.ty.is_region_ptr() || src.layout.ty.is_unsafe_ptr() || src.layout.ty.is_fn_ptr()) &&
dest_layout.ty.is_unsafe_ptr()
if src.layout.ty.is_any_ptr() && dest_layout.ty.is_unsafe_ptr()
{
// The only possible size-unequal case was handled above.
assert_eq!(src.layout.size, dest_layout.size);

View file

@ -302,7 +302,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let r = self.force_bits(right.to_scalar()?, right.layout.size)?;
self.binary_int_op(bin_op, l, left.layout, r, right.layout)
}
_ if left.layout.ty.is_unsafe_ptr() || left.layout.ty.is_fn_ptr() => {
_ if left.layout.ty.is_any_ptr() => {
// The RHS type must be the same *or an integer type* (for `Offset`)
assert!(
right.layout.ty == left.layout.ty || right.layout.ty.is_integral(),

View file

@ -1,4 +1,3 @@
fn main() {
// Make sure match uses the usual pointer comparison code path -- i.e., it should complain
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw