Skip to content

Commit

Permalink
Get rid of allow(static_mut_refs) in miri tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV committed Feb 19, 2024
1 parent 7e0db67 commit 859c122
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/tools/miri/tests/fail/tls/tls_static_dealloc.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
}
}
6 changes: 3 additions & 3 deletions src/tools/miri/tests/pass/static_mut.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
17 changes: 8 additions & 9 deletions src/tools/miri/tests/pass/tls/tls_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 859c122

Please sign in to comment.