1
Fork 0

Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors

Disallow hidden references to mutable static

Closes #123060

Tracking:
- https://github.com/rust-lang/rust/issues/123758
This commit is contained in:
bors 2024-09-20 17:25:34 +00:00
commit 5ba6db1b64
124 changed files with 1006 additions and 877 deletions

View file

@ -9,6 +9,9 @@
//! Consider the following code, operating on some global static variables:
//!
//! ```rust
//! // FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
//! #![allow(static_mut_refs)]
//!
//! static mut A: u32 = 0;
//! static mut B: u32 = 0;
//! static mut C: u32 = 0;

View file

@ -16,6 +16,9 @@
//! The crate itself provides a global allocator which on wasm has no
//! synchronization as there are no threads!
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]
use crate::alloc::{GlobalAlloc, Layout, System};
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();

View file

@ -103,6 +103,9 @@ fn smoke_dtor() {
#[test]
fn circular() {
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]
struct S1(&'static LocalKey<UnsafeCell<Option<S1>>>, &'static LocalKey<UnsafeCell<Option<S2>>>);
struct S2(&'static LocalKey<UnsafeCell<Option<S1>>>, &'static LocalKey<UnsafeCell<Option<S2>>>);
thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell::new(None));