diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 77b8ebba2166..14da3875cdd7 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -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`. #[inline] pub fn is_arc(&self) -> bool { diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index fb4329ee0e32..edddbc885006 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -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); diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index 504bd0a67bc4..24bb71241008 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -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(), diff --git a/src/test/ui/consts/const-eval/match-test-ptr-null.rs b/src/test/ui/consts/const-eval/match-test-ptr-null.rs index 9c930221e73e..5b89b0262aca 100644 --- a/src/test/ui/consts/const-eval/match-test-ptr-null.rs +++ b/src/test/ui/consts/const-eval/match-test-ptr-null.rs @@ -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