diff --git a/library/core/tests/alloc.rs b/library/core/tests/alloc.rs index 6762c0319e5cf92a561e8e69576103b7f5728fa9..8a5a06b3440f85cf33b614091b26759a442c90e9 100644 --- a/library/core/tests/alloc.rs +++ b/library/core/tests/alloc.rs @@ -1,5 +1,5 @@ use core::alloc::Layout; -use core::ptr::NonNull; +use core::ptr::{self, NonNull}; #[test] fn const_unchecked_layout() { @@ -9,7 +9,7 @@ fn const_unchecked_layout() { const DANGLING: NonNull = LAYOUT.dangling(); assert_eq!(LAYOUT.size(), SIZE); assert_eq!(LAYOUT.align(), ALIGN); - assert_eq!(Some(DANGLING), NonNull::new(ALIGN as *mut u8)); + assert_eq!(Some(DANGLING), NonNull::new(ptr::invalid_mut(ALIGN))); } #[test] diff --git a/library/core/tests/hash/mod.rs b/library/core/tests/hash/mod.rs index 5bc6aac1778f50a62249da8c9a5778d0b1fd09ab..f7934d062a3798051fbbbbf57bcefb832c5d3963 100644 --- a/library/core/tests/hash/mod.rs +++ b/library/core/tests/hash/mod.rs @@ -2,6 +2,7 @@ use std::default::Default; use std::hash::{BuildHasher, Hash, Hasher}; +use std::ptr; use std::rc::Rc; struct MyHasher { @@ -69,10 +70,10 @@ fn hash(t: &T) -> u64 { let cs: Rc<[u8]> = Rc::new([1, 2, 3]); assert_eq!(hash(&cs), 9); - let ptr = 5_usize as *const i32; + let ptr = ptr::invalid::(5_usize); assert_eq!(hash(&ptr), 5); - let ptr = 5_usize as *mut i32; + let ptr = ptr::invalid_mut::(5_usize); assert_eq!(hash(&ptr), 5); if cfg!(miri) { diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 3e2956eac8753064d4772cb55c18643ce53d8d2c..187a7db7fcb832e229b12e12359f65525adf27fb 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -353,9 +353,9 @@ fn align_offset_zst() { // all, because no amount of elements will align the pointer. let mut p = 1; while p < 1024 { - assert_eq!((p as *const ()).align_offset(p), 0); + assert_eq!(ptr::invalid::<()>(p).align_offset(p), 0); if p != 1 { - assert_eq!(((p + 1) as *const ()).align_offset(p), !0); + assert_eq!(ptr::invalid::<()>(p + 1).align_offset(p), !0); } p = (p + 1).next_power_of_two(); } @@ -371,7 +371,7 @@ fn align_offset_stride1() { let expected = ptr % align; let offset = if expected == 0 { 0 } else { align - expected }; assert_eq!( - (ptr as *const u8).align_offset(align), + ptr::invalid::(ptr).align_offset(align), offset, "ptr = {}, align = {}, size = 1", ptr, @@ -434,14 +434,14 @@ unsafe fn test_weird_stride(ptr: *const T, align: usize) -> bool { while align < limit { for ptr in 1usize..4 * align { unsafe { - x |= test_weird_stride::(ptr as *const A3, align); - x |= test_weird_stride::(ptr as *const A4, align); - x |= test_weird_stride::(ptr as *const A5, align); - x |= test_weird_stride::(ptr as *const A6, align); - x |= test_weird_stride::(ptr as *const A7, align); - x |= test_weird_stride::(ptr as *const A8, align); - x |= test_weird_stride::(ptr as *const A9, align); - x |= test_weird_stride::(ptr as *const A10, align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); + x |= test_weird_stride::(ptr::invalid::(ptr), align); } } align = (align + 1).next_power_of_two(); @@ -479,8 +479,8 @@ fn ptr_metadata() { let () = metadata(&[4, 7]); let () = metadata(&(4, String::new())); let () = metadata(&Pair(4, String::new())); - let () = metadata(0 as *const Extern); - let () = metadata(0 as *const <&u32 as std::ops::Deref>::Target); + let () = metadata(ptr::null::<()>() as *const Extern); + let () = metadata(ptr::null::<()>() as *const <&u32 as std::ops::Deref>::Target); assert_eq!(metadata("foo"), 3_usize); assert_eq!(metadata(&[4, 7][..]), 2_usize); diff --git a/library/core/tests/waker.rs b/library/core/tests/waker.rs index 6602ab36ba714c04a748ca4797a1a13a0a6b3efa..38a3a0adad98ebb898f717fa7a8a87502740de7f 100644 --- a/library/core/tests/waker.rs +++ b/library/core/tests/waker.rs @@ -3,7 +3,7 @@ #[test] fn test_waker_getters() { - let raw_waker = RawWaker::new(42usize as *mut (), &WAKER_VTABLE); + let raw_waker = RawWaker::new(ptr::invalid_mut(42usize), &WAKER_VTABLE); assert_eq!(raw_waker.data() as usize, 42); assert!(ptr::eq(raw_waker.vtable(), &WAKER_VTABLE)); @@ -15,7 +15,7 @@ fn test_waker_getters() { } static WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new( - |data| RawWaker::new((data as usize + 1) as *mut (), &WAKER_VTABLE), + |data| RawWaker::new(ptr::invalid_mut(data as usize + 1), &WAKER_VTABLE), |_| {}, |_| {}, |_| {},