about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-07-25 01:02:41 +0200
committerRalf Jung <post@ralfj.de>2019-08-02 23:04:11 +0200
commit7b30612c9bf8731abeb42eff684ae15f46a0656d (patch)
tree6d49654b414462b13b96c256b700001d42c03599
parent144e5e99b5854c15bb9908a61e38b23f66fb6b46 (diff)
add is_any_ptr type test; this also helps pacify tidy
-rw-r--r--src/librustc/ty/sty.rs6
-rw-r--r--src/librustc_mir/interpret/cast.rs6
-rw-r--r--src/librustc_mir/interpret/operator.rs2
-rw-r--r--src/test/ui/consts/const-eval/match-test-ptr-null.rs1
4 files changed, 9 insertions, 6 deletions
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index 77b8ebba216..14da3875cdd 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<T>`.
     #[inline]
     pub fn is_arc(&self) -> bool {
diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs
index fb4329ee0e3..edddbc88500 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 504bd0a67bc..24bb7124100 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 9c930221e73..5b89b0262ac 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