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
+6
View File
@@ -1863,6 +1863,12 @@ pub fn is_unsafe_ptr(&self) -> bool {
}
}
/// 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 {
+2 -4
View File
@@ -105,8 +105,7 @@ fn cast_immediate(
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 @@ fn cast_immediate(
}
// 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);
+1 -1
View File
@@ -302,7 +302,7 @@ pub fn binary_op(
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(),
@@ -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