diff --git a/src/tools/miri/tests/fail/tls/tls_static_dealloc.rs b/src/tools/miri/tests/fail/tls/tls_static_dealloc.rs index d47a05d8475cf..c72cc8114dac4 100644 --- a/src/tools/miri/tests/fail/tls/tls_static_dealloc.rs +++ b/src/tools/miri/tests/fail/tls/tls_static_dealloc.rs @@ -1,8 +1,8 @@ //! Ensure that thread-local statics get deallocated when the thread dies. #![feature(thread_local)] -// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint -#![allow(static_mut_refs)] + +use std::ptr::addr_of; #[thread_local] static mut TLS: u8 = 0; @@ -12,7 +12,7 @@ unsafe impl Send for SendRaw {} fn main() { unsafe { - let dangling_ptr = std::thread::spawn(|| SendRaw(&TLS as *const u8)).join().unwrap(); + let dangling_ptr = std::thread::spawn(|| SendRaw(addr_of!(TLS))).join().unwrap(); let _val = *dangling_ptr.0; //~ ERROR: has been freed } } diff --git a/src/tools/miri/tests/pass/static_mut.rs b/src/tools/miri/tests/pass/static_mut.rs index 6b0c0297726f3..1b416cc4e9b08 100644 --- a/src/tools/miri/tests/pass/static_mut.rs +++ b/src/tools/miri/tests/pass/static_mut.rs @@ -1,8 +1,8 @@ +use std::ptr::addr_of; + static mut FOO: i32 = 42; -// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint -#[allow(static_mut_refs)] -static BAR: Foo = Foo(unsafe { &FOO as *const _ }); +static BAR: Foo = Foo(unsafe { addr_of!(FOO) }); #[allow(dead_code)] struct Foo(*const i32); diff --git a/src/tools/miri/tests/pass/tls/tls_static.rs b/src/tools/miri/tests/pass/tls/tls_static.rs index fea5bb1db5e6b..8d0e5089d404a 100644 --- a/src/tools/miri/tests/pass/tls/tls_static.rs +++ b/src/tools/miri/tests/pass/tls/tls_static.rs @@ -8,9 +8,8 @@ //! test, we also check that thread-locals act as per-thread statics. #![feature(thread_local)] -// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint -#![allow(static_mut_refs)] +use std::ptr::addr_of_mut; use std::thread; #[thread_local] @@ -23,8 +22,8 @@ static mut C: u8 = 0; #[thread_local] static READ_ONLY: u8 = 42; -unsafe fn get_a_ref() -> *mut u8 { - &mut A +unsafe fn get_a_ptr() -> *mut u8 { + addr_of_mut!(A) } struct Sender(*mut u8); @@ -35,12 +34,12 @@ fn main() { let _val = READ_ONLY; let ptr = unsafe { - let x = get_a_ref(); + let x = get_a_ptr(); *x = 5; assert_eq!(A, 5); B = 15; C = 25; - Sender(&mut A) + Sender(addr_of_mut!(A)) }; thread::spawn(move || unsafe { @@ -51,18 +50,18 @@ fn main() { assert_eq!(C, 25); B = 14; C = 24; - let y = get_a_ref(); + let y = get_a_ptr(); assert_eq!(*y, 0); *y = 4; assert_eq!(*ptr.0, 5); assert_eq!(A, 4); - assert_eq!(*get_a_ref(), 4); + assert_eq!(*get_a_ptr(), 4); }) .join() .unwrap(); unsafe { - assert_eq!(*get_a_ref(), 5); + assert_eq!(*get_a_ptr(), 5); assert_eq!(A, 5); assert_eq!(B, 15); assert_eq!(C, 24);