Skip to content

Commit 7d2fd98

Browse files
committed
Update test
1 parent d97f0a1 commit 7d2fd98

30 files changed

+313
-15
lines changed

compiler/rustc_driver_impl/src/signal_handler.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ macro raw_errln($tokens:tt) {
3434
}
3535

3636
/// Signal handler installed for SIGSEGV
37+
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
38+
#[allow(static_mut_refs)]
3739
extern "C" fn print_stack_trace(_: libc::c_int) {
3840
const MAX_FRAMES: usize = 256;
3941
// Reserve data segment so we don't have to malloc in a signal handler, which might fail

library/alloc/tests/vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,8 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {
12851285

12861286
#[test]
12871287
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
1288+
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
1289+
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
12881290
fn test_from_iter_specialization_panic_during_drop_doesnt_leak() {
12891291
static mut DROP_COUNTER_OLD: [usize; 5] = [0; 5];
12901292
static mut DROP_COUNTER_NEW: [usize; 2] = [0; 2];

library/core/tests/atomic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ fn static_init() {
228228
}
229229

230230
#[test]
231+
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
232+
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
231233
fn atomic_access_bool() {
232234
static mut ATOMIC: AtomicBool = AtomicBool::new(false);
233235

src/tools/tidy/src/issues.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,6 @@ ui/issues/issue-17068.rs
16521652
ui/issues/issue-17121.rs
16531653
ui/issues/issue-17216.rs
16541654
ui/issues/issue-17252.rs
1655-
ui/issues/issue-17302.rs
16561655
ui/issues/issue-17322.rs
16571656
ui/issues/issue-17336.rs
16581657
ui/issues/issue-17337.rs

tests/ui/async-await/issues/issue-67611-static-mut-refs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn is_send_sync<T: Send + Sync>(_: T) {}
99

1010
async fn fun() {
1111
let u = unsafe { A[async { 1 }.await] };
12+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
1213
unsafe {
1314
match A {
1415
i if async { true }.await => (),
@@ -21,6 +22,7 @@ async fn fun() {
2122
fn main() {
2223
let index_block = async {
2324
let u = unsafe { A[async { 1 }.await] };
25+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2426
};
2527
let match_block = async {
2628
unsafe {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/issue-67611-static-mut-refs.rs:11:22
3+
|
4+
LL | let u = unsafe { A[async { 1 }.await] };
5+
| ^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
12+
warning: creating a shared reference to mutable static is discouraged
13+
--> $DIR/issue-67611-static-mut-refs.rs:24:26
14+
|
15+
LL | let u = unsafe { A[async { 1 }.await] };
16+
| ^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
17+
|
18+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
19+
= note: this will be a hard error in the 2024 edition
20+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
21+
22+
warning: 2 warnings emitted
23+

tests/ui/binding/order-drop-with-match.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl Drop for A {
1414
fn drop(&mut self) {
1515
unsafe {
1616
ORDER[INDEX] = 1;
17+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
1718
INDEX = INDEX + 1;
1819
}
1920
}
@@ -24,6 +25,7 @@ impl Drop for B {
2425
fn drop(&mut self) {
2526
unsafe {
2627
ORDER[INDEX] = 2;
28+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2729
INDEX = INDEX + 1;
2830
}
2931
}
@@ -34,6 +36,7 @@ impl Drop for C {
3436
fn drop(&mut self) {
3537
unsafe {
3638
ORDER[INDEX] = 3;
39+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
3740
INDEX = INDEX + 1;
3841
}
3942
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/order-drop-with-match.rs:16:13
3+
|
4+
LL | ORDER[INDEX] = 1;
5+
| ^^^^^^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
12+
warning: creating a shared reference to mutable static is discouraged
13+
--> $DIR/order-drop-with-match.rs:27:13
14+
|
15+
LL | ORDER[INDEX] = 2;
16+
| ^^^^^^^^^^^^ shared reference to mutable static
17+
|
18+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
19+
= note: this will be a hard error in the 2024 edition
20+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
21+
22+
warning: creating a shared reference to mutable static is discouraged
23+
--> $DIR/order-drop-with-match.rs:38:13
24+
|
25+
LL | ORDER[INDEX] = 3;
26+
| ^^^^^^^^^^^^ shared reference to mutable static
27+
|
28+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
29+
= note: this will be a hard error in the 2024 edition
30+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
31+
32+
warning: 3 warnings emitted
33+

tests/ui/consts/static-mut-refs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ static mut INT_RAW: *mut isize = &mut 1isize as *mut _;
1717
pub fn main() {
1818
unsafe {
1919
TEST[0] += 1;
20+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2021
assert_eq!(TEST[0], 2);
22+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2123
*INT_RAW += 1;
2224
assert_eq!(*INT_RAW, 2);
2325
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/static-mut-refs.rs:19:9
3+
|
4+
LL | TEST[0] += 1;
5+
| ^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
12+
warning: creating a shared reference to mutable static is discouraged
13+
--> $DIR/static-mut-refs.rs:21:20
14+
|
15+
LL | assert_eq!(TEST[0], 2);
16+
| ^^^^^^^ shared reference to mutable static
17+
|
18+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
19+
= note: this will be a hard error in the 2024 edition
20+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
21+
22+
warning: 2 warnings emitted
23+

tests/ui/coroutine/static-mut-reference-across-yield.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
unsafe {
1111
let gen_index = #[coroutine]
1212
static || {
13-
let u = A[{
13+
let u = A[{ //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
1414
yield;
1515
1
1616
}];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/static-mut-reference-across-yield.rs:13:21
3+
|
4+
LL | let u = A[{
5+
| _____________________^
6+
LL | | yield;
7+
LL | | 1
8+
LL | | }];
9+
| |______________^ shared reference to mutable static
10+
|
11+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
12+
= note: this will be a hard error in the 2024 edition
13+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
14+
= note: `#[warn(static_mut_refs)]` on by default
15+
16+
warning: 1 warning emitted
17+

tests/ui/drop/issue-23338-ensure-param-drop-order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub mod d {
8585
pub type Log<'a> = &'a RefCell<Vec<u32>>;
8686

8787
pub fn current_width() -> u32 {
88-
unsafe { max_width() - trails.leading_zeros() }
88+
unsafe { max_width() - trails.leading_zeros() } //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
8989
}
9090

9191
pub fn max_width() -> u32 {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/issue-23338-ensure-param-drop-order.rs:88:32
3+
|
4+
LL | ... unsafe { max_width() - trails.leading_zeros() }
5+
| ^^^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
112
warning: creating a shared reference to mutable static is discouraged
213
--> $DIR/issue-23338-ensure-param-drop-order.rs:93:31
314
|
@@ -7,11 +18,10 @@ LL | (mem::size_of_val(&trails) * 8) as u32
718
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
819
= note: this will be a hard error in the 2024 edition
920
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10-
= note: `#[warn(static_mut_refs)]` on by default
1121
help: use `addr_of!` instead to create a raw pointer
1222
|
1323
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
1424
| ~~~~~~~~~~~~~~~~
1525

16-
warning: 1 warning emitted
26+
warning: 2 warnings emitted
1727

tests/ui/drop/issue-23611-enum-swap-in-drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub mod d {
181181
pub type Log<'a> = &'a RefCell<Vec<u32>>;
182182

183183
pub fn current_width() -> u32 {
184-
unsafe { max_width() - trails.leading_zeros() }
184+
unsafe { max_width() - trails.leading_zeros() } //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
185185
}
186186

187187
pub fn max_width() -> u32 {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/issue-23611-enum-swap-in-drop.rs:184:32
3+
|
4+
LL | ... unsafe { max_width() - trails.leading_zeros() }
5+
| ^^^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
112
warning: creating a shared reference to mutable static is discouraged
213
--> $DIR/issue-23611-enum-swap-in-drop.rs:189:31
314
|
@@ -7,11 +18,10 @@ LL | (mem::size_of_val(&trails) * 8) as u32
718
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
819
= note: this will be a hard error in the 2024 edition
920
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10-
= note: `#[warn(static_mut_refs)]` on by default
1121
help: use `addr_of!` instead to create a raw pointer
1222
|
1323
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
1424
| ~~~~~~~~~~~~~~~~
1525

16-
warning: 1 warning emitted
26+
warning: 2 warnings emitted
1727

tests/ui/drop/issue-48962.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl Drop for Dropee {
1010
fn drop(&mut self) {
1111
unsafe {
1212
ORDER[INDEX] = self.0;
13+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
1314
INDEX = INDEX + 1;
1415
}
1516
}
@@ -18,6 +19,7 @@ impl Drop for Dropee {
1819
fn add_sentintel() {
1920
unsafe {
2021
ORDER[INDEX] = 2;
22+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2123
INDEX = INDEX + 1;
2224
}
2325
}

tests/ui/drop/issue-48962.stderr

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/issue-48962.rs:12:13
3+
|
4+
LL | ORDER[INDEX] = self.0;
5+
| ^^^^^^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
12+
warning: creating a shared reference to mutable static is discouraged
13+
--> $DIR/issue-48962.rs:21:9
14+
|
15+
LL | ORDER[INDEX] = 2;
16+
| ^^^^^^^^^^^^ shared reference to mutable static
17+
|
18+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
19+
= note: this will be a hard error in the 2024 edition
20+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
21+
22+
warning: 2 warnings emitted
23+

tests/ui/issues/issue-17302.rs renamed to tests/ui/drop/static-issue-17302.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ impl Drop for A {
99
fn drop(&mut self) {
1010
let A(i) = *self;
1111
unsafe { DROPPED[i] = true; }
12+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
1213
}
1314
}
1415

@@ -21,6 +22,8 @@ fn main() {
2122
}
2223
unsafe {
2324
assert!(DROPPED[0]);
25+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2426
assert!(DROPPED[1]);
27+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2528
}
2629
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/static-issue-17302.rs:11:18
3+
|
4+
LL | unsafe { DROPPED[i] = true; }
5+
| ^^^^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
12+
warning: creating a shared reference to mutable static is discouraged
13+
--> $DIR/static-issue-17302.rs:24:17
14+
|
15+
LL | assert!(DROPPED[0]);
16+
| ^^^^^^^^^^ shared reference to mutable static
17+
|
18+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
19+
= note: this will be a hard error in the 2024 edition
20+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
21+
22+
warning: creating a shared reference to mutable static is discouraged
23+
--> $DIR/static-issue-17302.rs:26:17
24+
|
25+
LL | assert!(DROPPED[1]);
26+
| ^^^^^^^^^^ shared reference to mutable static
27+
|
28+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
29+
= note: this will be a hard error in the 2024 edition
30+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
31+
32+
warning: 3 warnings emitted
33+

tests/ui/functional-struct-update/functional-struct-update-respects-privacy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod foo {
1212

1313
pub fn make_secrets(a: u8, b: String) -> S {
1414
let val = unsafe { let p = COUNT.get(); let val = *p; *p = val + 1; val };
15+
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
1516
println!("creating {}, uid {}", b, val);
1617
S { a: a, b: b, secret_uid: val }
1718
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
warning: creating a shared reference to mutable static is discouraged
2+
--> $DIR/functional-struct-update-respects-privacy.rs:14:36
3+
|
4+
LL | let val = unsafe { let p = COUNT.get(); let val = *p; *p = val + 1; val };
5+
| ^^^^^^^^^^^ shared reference to mutable static
6+
|
7+
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
8+
= note: this will be a hard error in the 2024 edition
9+
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
10+
= note: `#[warn(static_mut_refs)]` on by default
11+
112
error[E0451]: field `secret_uid` of struct `S` is private
2-
--> $DIR/functional-struct-update-respects-privacy.rs:28:49
13+
--> $DIR/functional-struct-update-respects-privacy.rs:29:49
314
|
415
LL | let s_2 = foo::S { b: format!("ess two"), ..s_1 }; // FRU ...
516
| ^^^ field `secret_uid` is private
617

7-
error: aborting due to 1 previous error
18+
error: aborting due to 1 previous error; 1 warning emitted
819

920
For more information about this error, try `rustc --explain E0451`.

tests/ui/issues/issue-39367.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn arena() -> &'static ArenaSet<Vec<u8>> {
1919
static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();
2020

2121
static mut ONCE: Once = Once::new();
22-
ONCE.call_once(|| {
22+
ONCE.call_once(|| { //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
2323
DATA = transmute
2424
::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
2525
(Box::new(__static_ref_initialize()));

0 commit comments

Comments
 (0)