about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-23 18:52:47 +0000
committerbors <bors@rust-lang.org>2024-02-23 18:52:47 +0000
commit2dbd6233ccdb2cd4b621a5e839a95c3fbbc0c375 (patch)
tree1eed8d33bc342172e0a9ccd589852f2409311dc9 /src
parent21033f637e60af61ead04cc296e7214f89c16a95 (diff)
parent58c8c0853f08d83a86edfc9cd73463ff29f0509f (diff)
Auto merge of #121303 - GrigorenkoPV:static_mut_refs, r=oli-obk,RalfJung
Get rid of some `#![allow(static_mut_refs)]`
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/tests/fail/tls/tls_static_dealloc.rs6
-rw-r--r--src/tools/miri/tests/pass/static_mut.rs6
-rw-r--r--src/tools/miri/tests/pass/tls/tls_static.rs17
3 files changed, 14 insertions, 15 deletions
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 d47a05d8475..c72cc8114da 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 6b0c0297726..1b416cc4e9b 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 fea5bb1db5e..8d0e5089d40 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);