Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 302a109

Browse files
committed
Update test for E0796 and static_mut_ref lint
1 parent cd07eb1 commit 302a109

File tree

51 files changed

+786
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+786
-239
lines changed

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ fn start<T: Termination + 'static>(
111111
}
112112

113113
static mut NUM: u8 = 6 * 7;
114+
115+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
116+
#[allow(static_mut_ref)]
114117
static NUM_REF: &'static u8 = unsafe { &NUM };
115118

116119
unsafe fn zeroed<T>() -> T {

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ fn start<T: Termination + 'static>(
9898
}
9999

100100
static mut NUM: u8 = 6 * 7;
101+
102+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
103+
#[allow(static_mut_ref)]
101104
static NUM_REF: &'static u8 = unsafe { &NUM };
102105

103106
macro_rules! assert {

library/panic_unwind/src/seh.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ cfg_if::cfg_if! {
261261
}
262262
}
263263

264+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
265+
#[allow(static_mut_ref)]
264266
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
265267
use core::intrinsics::atomic_store_seqcst;
266268

@@ -322,6 +324,8 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
322324
_CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
323325
}
324326

327+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
328+
#[allow(static_mut_ref)]
325329
pub unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send> {
326330
// A null payload here means that we got here from the catch (...) of
327331
// __rust_try. This happens when a non-Rust foreign exception is caught.

library/std/src/sys/common/thread_local/fast_local.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub macro thread_local_inner {
1313
(@key $t:ty, const $init:expr) => {{
1414
#[inline]
1515
#[deny(unsafe_op_in_unsafe_fn)]
16+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
17+
#[cfg_attr(not(bootstrap), allow(static_mut_ref))]
1618
unsafe fn __getit(
1719
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
1820
) -> $crate::option::Option<&'static $t> {

src/tools/lint-docs/src/groups.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[
1515
("future-incompatible", "Lints that detect code that has future-compatibility problems"),
1616
("rust-2018-compatibility", "Lints used to transition code from the 2015 edition to 2018"),
1717
("rust-2021-compatibility", "Lints used to transition code from the 2018 edition to 2021"),
18+
("rust-2024-compatibility", "Lints used to transition code from the 2021 edition to 2024"),
1819
];
1920

2021
type LintGroups = BTreeMap<String, BTreeSet<String>>;

src/tools/miri/tests/fail/tls/tls_static_dealloc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Ensure that thread-local statics get deallocated when the thread dies.
22
33
#![feature(thread_local)]
4+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
5+
#![allow(static_mut_ref)]
46

57
#[thread_local]
68
static mut TLS: u8 = 0;

src/tools/miri/tests/pass/static_mut.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
static mut FOO: i32 = 42;
2+
3+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
4+
#[allow(static_mut_ref)]
25
static BAR: Foo = Foo(unsafe { &FOO as *const _ });
36

47
#[allow(dead_code)]

src/tools/miri/tests/pass/tls/tls_static.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
//! test, we also check that thread-locals act as per-thread statics.
99
1010
#![feature(thread_local)]
11+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
12+
#![allow(static_mut_ref)]
1113

1214
use std::thread;
1315

tests/ui/abi/statics/static-mut-foreign.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ unsafe fn run() {
3333
rust_dbg_static_mut = -3;
3434
assert_eq!(rust_dbg_static_mut, -3);
3535
static_bound(&rust_dbg_static_mut);
36+
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
3637
static_bound_set(&mut rust_dbg_static_mut);
38+
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
3739
}
3840

3941
pub fn main() {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
warning: shared reference of mutable static is discouraged
2+
--> $DIR/static-mut-foreign.rs:35:18
3+
|
4+
LL | static_bound(&rust_dbg_static_mut);
5+
| ^^^^^^^^^^^^^^^^^^^^ shared reference of mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: reference of mutable static is a hard error from 2024 edition
9+
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
10+
= note: `#[warn(static_mut_ref)]` on by default
11+
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
12+
|
13+
LL | static_bound(addr_of!(rust_dbg_static_mut));
14+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
warning: mutable reference of mutable static is discouraged
17+
--> $DIR/static-mut-foreign.rs:37:22
18+
|
19+
LL | static_bound_set(&mut rust_dbg_static_mut);
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference of mutable static
21+
|
22+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
23+
= note: reference of mutable static is a hard error from 2024 edition
24+
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
25+
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
26+
|
27+
LL | static_bound_set(addr_of_mut!(rust_dbg_static_mut));
28+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
30+
warning: 2 warnings emitted
31+

0 commit comments

Comments
 (0)