Skip to content

Commit

Permalink
Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors
Browse files Browse the repository at this point in the history
Disallow hidden references to mutable static

Closes #123060

Tracking:
- rust-lang/rust#123758
  • Loading branch information
bors committed Sep 20, 2024
2 parents ff3b2d0 + f9d2e9d commit c3a1291
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/pass-dep/concurrency/linux-futex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@only-target: linux
//@compile-flags: -Zmiri-disable-isolation

// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::mem::MaybeUninit;
use std::ptr::{self, addr_of};
use std::sync::atomic::AtomicI32;
Expand Down
3 changes: 3 additions & 0 deletions tests/pass-dep/concurrency/tls_pthread_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//! the fallback path in `guard::key::enable`, which uses a *single* pthread_key
//! to manage a thread-local list of dtors to call.
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::mem;
use std::ptr;

Expand Down
3 changes: 3 additions & 0 deletions tests/pass-dep/libc/libc-eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// test_race depends on a deterministic schedule.
//@compile-flags: -Zmiri-preemption-rate=0

// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::thread;

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions tests/pass-dep/libc/libc-pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ fn test_pipe_threaded() {
thread2.join().unwrap();
}

// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#[allow(static_mut_refs)]
fn test_race() {
static mut VAL: u8 = 0;
let mut fds = [-1, -1];
Expand Down
4 changes: 4 additions & 0 deletions tests/pass-dep/libc/libc-socketpair.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//@ignore-target: windows # No libc socketpair on Windows
// test_race depends on a deterministic schedule.
//@compile-flags: -Zmiri-preemption-rate=0

// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::thread;
fn main() {
test_socketpair();
Expand Down
4 changes: 4 additions & 0 deletions tests/pass/atomic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
//@compile-flags: -Zmiri-strict-provenance

#![feature(strict_provenance, strict_provenance_atomic_ptr)]
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::sync::atomic::{
compiler_fence, fence, AtomicBool, AtomicIsize, AtomicPtr, AtomicU64, Ordering::*,
};
Expand Down
2 changes: 2 additions & 0 deletions tests/pass/drop_on_array_elements.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(static_mut_refs)]

struct Bar(u16); // ZSTs are tested separately

static mut DROP_COUNT: usize = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/pass/drop_on_fat_ptr_array_elements.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(static_mut_refs)]

trait Foo {}

struct Bar;
Expand Down
2 changes: 2 additions & 0 deletions tests/pass/drop_on_zst_array_elements.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(static_mut_refs)]

struct Bar;

static mut DROP_COUNT: usize = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/pass/drop_through_owned_slice.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(static_mut_refs)]

struct Bar;

static mut DROP_COUNT: usize = 0;
Expand Down
3 changes: 3 additions & 0 deletions tests/pass/static_memory_modification.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::sync::atomic::{AtomicUsize, Ordering};

static mut X: usize = 5;
Expand Down
3 changes: 3 additions & 0 deletions tests/pass/static_mut.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::ptr::addr_of;

static mut FOO: i32 = 42;
Expand Down
2 changes: 2 additions & 0 deletions tests/pass/tls/tls_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//! dereferencing the pointer on `t2` resolves to `t1`'s thread-local. In this
//! test, we also check that thread-locals act as per-thread statics.
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]
#![feature(thread_local)]

use std::ptr::addr_of_mut;
Expand Down

0 comments on commit c3a1291

Please sign in to comment.