Skip to content

Commit fa621b7

Browse files
committed
Update tests for hidden references to mutable static
1 parent 5cee9da commit fa621b7

File tree

96 files changed

+1201
-475
lines changed

Some content is hidden

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

96 files changed

+1201
-475
lines changed

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

library/panic_unwind/src/seh.rs

+2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ cfg_if::cfg_if! {
297297
}
298298
}
299299

300+
// FIXME(obeis): Do not allow `static_mut_refs` lint
301+
#[allow(static_mut_refs)]
300302
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
301303
use core::intrinsics::atomic_store_seqcst;
302304

library/std/src/sync/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
//! Consider the following code, operating on some global static variables:
1010
//!
1111
//! ```rust
12+
//! // FIXME(obeis): Do not allow `static_mut_refs` lint
13+
//! #![allow(static_mut_refs)]
14+
//!
1215
//! static mut A: u32 = 0;
1316
//! static mut B: u32 = 0;
1417
//! static mut C: u32 = 0;

library/std/src/sys/pal/wasm/alloc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
//! The crate itself provides a global allocator which on wasm has no
1717
//! synchronization as there are no threads!
1818
19+
// FIXME(obeis): Do not allow `static_mut_refs` lint
20+
#![allow(static_mut_refs)]
21+
1922
use crate::alloc::{GlobalAlloc, Layout, System};
2023

2124
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();

library/std/src/thread/local/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ fn smoke_dtor() {
103103

104104
#[test]
105105
fn circular() {
106+
// FIXME(obeis): Do not allow `static_mut_refs` lint
107+
#![allow(static_mut_refs)]
108+
106109
struct S1(&'static LocalKey<UnsafeCell<Option<S1>>>, &'static LocalKey<UnsafeCell<Option<S2>>>);
107110
struct S2(&'static LocalKey<UnsafeCell<Option<S1>>>, &'static LocalKey<UnsafeCell<Option<S2>>>);
108111
thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell::new(None));

src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ fn issue11371() {
172172
static mut X: Option<i32> = Some(123);
173173
unsafe {
174174
if X.is_some() {
175+
//~^ ERROR: creating a shared reference to mutable static is discouraged
175176
X = None;
176177
X.unwrap();
177178
}

src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error: creating a shared reference to mutable static is discouraged
2+
--> tests/ui/checked_unwrap/simple_conditionals.rs:174:12
3+
|
4+
LL | if X.is_some() {
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: shared references to mutable statics are dangerous since if there's any kind of mutation of, or mutable reference created for, that static while the reference lives, that's undefined behavior
10+
= note: `-D static-mut-refs` implied by `-D warnings`
11+
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`
12+
113
error: called `unwrap` on `x` after checking its variant with `is_some`
214
--> tests/ui/checked_unwrap/simple_conditionals.rs:46:9
315
|
@@ -236,5 +248,5 @@ LL | if result.is_ok() {
236248
LL | result.as_mut().unwrap();
237249
| ^^^^^^^^^^^^^^^^^^^^^^^^
238250

239-
error: aborting due to 25 previous errors
251+
error: aborting due to 26 previous errors
240252

src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![allow(unused)]
2+
// FIXME(obeis): Do not allow `static_mut_refs` lint
3+
#![allow(static_mut_refs)]
24

35
#[derive(Debug)]
46
struct Foo;

src/tools/clippy/tests/ui/redundant_static_lifetimes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![allow(unused)]
2+
// FIXME(obeis): Do not allow `static_mut_refs` lint
3+
#![allow(static_mut_refs)]
24

35
#[derive(Debug)]
46
struct Foo;

src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: constants have by default a `'static` lifetime
2-
--> tests/ui/redundant_static_lifetimes.rs:6:17
2+
--> tests/ui/redundant_static_lifetimes.rs:8:17
33
|
44
LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static.
55
| -^^^^^^^---- help: consider removing `'static`: `&str`
@@ -8,103 +8,103 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removi
88
= help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]`
99

1010
error: constants have by default a `'static` lifetime
11-
--> tests/ui/redundant_static_lifetimes.rs:10:21
11+
--> tests/ui/redundant_static_lifetimes.rs:12:21
1212
|
1313
LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static
1414
| -^^^^^^^---- help: consider removing `'static`: `&str`
1515

1616
error: constants have by default a `'static` lifetime
17-
--> tests/ui/redundant_static_lifetimes.rs:12:32
17+
--> tests/ui/redundant_static_lifetimes.rs:14:32
1818
|
1919
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static
2020
| -^^^^^^^---- help: consider removing `'static`: `&str`
2121

2222
error: constants have by default a `'static` lifetime
23-
--> tests/ui/redundant_static_lifetimes.rs:12:47
23+
--> tests/ui/redundant_static_lifetimes.rs:14:47
2424
|
2525
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static
2626
| -^^^^^^^---- help: consider removing `'static`: `&str`
2727

2828
error: constants have by default a `'static` lifetime
29-
--> tests/ui/redundant_static_lifetimes.rs:14:17
29+
--> tests/ui/redundant_static_lifetimes.rs:16:17
3030
|
3131
LL | const VAR_SIX: &'static u8 = &5;
3232
| -^^^^^^^--- help: consider removing `'static`: `&u8`
3333

3434
error: constants have by default a `'static` lifetime
35-
--> tests/ui/redundant_static_lifetimes.rs:16:20
35+
--> tests/ui/redundant_static_lifetimes.rs:18:20
3636
|
3737
LL | const VAR_HEIGHT: &'static Foo = &Foo {};
3838
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
3939

4040
error: constants have by default a `'static` lifetime
41-
--> tests/ui/redundant_static_lifetimes.rs:18:19
41+
--> tests/ui/redundant_static_lifetimes.rs:20:19
4242
|
4343
LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR: Consider removing 'static.
4444
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
4545

4646
error: constants have by default a `'static` lifetime
47-
--> tests/ui/redundant_static_lifetimes.rs:20:19
47+
--> tests/ui/redundant_static_lifetimes.rs:22:19
4848
|
4949
LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
5050
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
5151

5252
error: constants have by default a `'static` lifetime
53-
--> tests/ui/redundant_static_lifetimes.rs:22:19
53+
--> tests/ui/redundant_static_lifetimes.rs:24:19
5454
|
5555
LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static.
5656
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
5757

5858
error: statics have by default a `'static` lifetime
59-
--> tests/ui/redundant_static_lifetimes.rs:24:25
59+
--> tests/ui/redundant_static_lifetimes.rs:26:25
6060
|
6161
LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR: Consider removing 'static.
6262
| -^^^^^^^---- help: consider removing `'static`: `&str`
6363

6464
error: statics have by default a `'static` lifetime
65-
--> tests/ui/redundant_static_lifetimes.rs:28:29
65+
--> tests/ui/redundant_static_lifetimes.rs:30:29
6666
|
6767
LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static
6868
| -^^^^^^^---- help: consider removing `'static`: `&str`
6969

7070
error: statics have by default a `'static` lifetime
71-
--> tests/ui/redundant_static_lifetimes.rs:30:25
71+
--> tests/ui/redundant_static_lifetimes.rs:32:25
7272
|
7373
LL | static STATIC_VAR_SIX: &'static u8 = &5;
7474
| -^^^^^^^--- help: consider removing `'static`: `&u8`
7575

7676
error: statics have by default a `'static` lifetime
77-
--> tests/ui/redundant_static_lifetimes.rs:32:28
77+
--> tests/ui/redundant_static_lifetimes.rs:34:28
7878
|
7979
LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
8080
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
8181

8282
error: statics have by default a `'static` lifetime
83-
--> tests/ui/redundant_static_lifetimes.rs:34:27
83+
--> tests/ui/redundant_static_lifetimes.rs:36:27
8484
|
8585
LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR: Consider removing 'static.
8686
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
8787

8888
error: statics have by default a `'static` lifetime
89-
--> tests/ui/redundant_static_lifetimes.rs:36:27
89+
--> tests/ui/redundant_static_lifetimes.rs:38:27
9090
|
9191
LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
9292
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
9393

9494
error: statics have by default a `'static` lifetime
95-
--> tests/ui/redundant_static_lifetimes.rs:38:27
95+
--> tests/ui/redundant_static_lifetimes.rs:40:27
9696
|
9797
LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static.
9898
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
9999

100100
error: statics have by default a `'static` lifetime
101-
--> tests/ui/redundant_static_lifetimes.rs:40:31
101+
--> tests/ui/redundant_static_lifetimes.rs:42:31
102102
|
103103
LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
104104
| -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]`
105105

106106
error: statics have by default a `'static` lifetime
107-
--> tests/ui/redundant_static_lifetimes.rs:69:16
107+
--> tests/ui/redundant_static_lifetimes.rs:71:16
108108
|
109109
LL | static V: &'static u8 = &17;
110110
| -^^^^^^^--- help: consider removing `'static`: `&u8`

src/tools/clippy/tests/ui/useless_conversion.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![deny(clippy::useless_conversion)]
22
#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
3+
// FIXME(obeis): Do not allow `static_mut_refs` lint
4+
#![allow(static_mut_refs)]
35

46
fn test_generic<T: Copy>(val: T) -> T {
57
let _ = val;

src/tools/clippy/tests/ui/useless_conversion.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![deny(clippy::useless_conversion)]
22
#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
3+
// FIXME(obeis): Do not allow `static_mut_refs` lint
4+
#![allow(static_mut_refs)]
35

46
fn test_generic<T: Copy>(val: T) -> T {
57
let _ = T::from(val);

0 commit comments

Comments
 (0)