Skip to content

Commit 7b30612

Browse files
committed
add is_any_ptr type test; this also helps pacify tidy
1 parent 144e5e9 commit 7b30612

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/librustc/ty/sty.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,12 @@ impl<'tcx> TyS<'tcx> {
18631863
}
18641864
}
18651865

1866+
/// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
1867+
#[inline]
1868+
pub fn is_any_ptr(&self) -> bool {
1869+
self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr()
1870+
}
1871+
18661872
/// Returns `true` if this type is an `Arc<T>`.
18671873
#[inline]
18681874
pub fn is_arc(&self) -> bool {

src/librustc_mir/interpret/cast.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
105105
assert!(
106106
src.layout.ty.is_bool() || src.layout.ty.is_char() ||
107107
src.layout.ty.is_enum() || src.layout.ty.is_integral() ||
108-
src.layout.ty.is_unsafe_ptr() || src.layout.ty.is_fn_ptr() ||
109-
src.layout.ty.is_region_ptr(),
108+
src.layout.ty.is_any_ptr(),
110109
"Unexpected cast from type {:?}", src.layout.ty
111110
)
112111
}
@@ -143,8 +142,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
143142
}
144143

145144
// Handle casting any ptr to raw ptr (might be a fat ptr).
146-
if (src.layout.ty.is_region_ptr() || src.layout.ty.is_unsafe_ptr() || src.layout.ty.is_fn_ptr()) &&
147-
dest_layout.ty.is_unsafe_ptr()
145+
if src.layout.ty.is_any_ptr() && dest_layout.ty.is_unsafe_ptr()
148146
{
149147
// The only possible size-unequal case was handled above.
150148
assert_eq!(src.layout.size, dest_layout.size);

src/librustc_mir/interpret/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
302302
let r = self.force_bits(right.to_scalar()?, right.layout.size)?;
303303
self.binary_int_op(bin_op, l, left.layout, r, right.layout)
304304
}
305-
_ if left.layout.ty.is_unsafe_ptr() || left.layout.ty.is_fn_ptr() => {
305+
_ if left.layout.ty.is_any_ptr() => {
306306
// The RHS type must be the same *or an integer type* (for `Offset`)
307307
assert!(
308308
right.layout.ty == left.layout.ty || right.layout.ty.is_integral(),

src/test/ui/consts/const-eval/match-test-ptr-null.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
fn main() {
32
// Make sure match uses the usual pointer comparison code path -- i.e., it should complain
43
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw

0 commit comments

Comments
 (0)