Skip to content

Commit

Permalink
Update tests for hidden references to mutable static
Browse files Browse the repository at this point in the history
  • Loading branch information
obeis committed Jul 26, 2024
1 parent 5cee9da commit 74561dc
Show file tree
Hide file tree
Showing 96 changed files with 1,201 additions and 475 deletions.
2 changes: 2 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,8 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {

#[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
fn test_from_iter_specialization_panic_during_drop_doesnt_leak() {
static mut DROP_COUNTER_OLD: [usize; 5] = [0; 5];
static mut DROP_COUNTER_NEW: [usize; 2] = [0; 2];
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ fn static_init() {
}

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

Expand Down
2 changes: 2 additions & 0 deletions library/panic_unwind/src/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ cfg_if::cfg_if! {
}
}

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

Expand Down
3 changes: 3 additions & 0 deletions library/std/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
//! Consider the following code, operating on some global static variables:
//!
//! ```rust
//! // FIXME(obeis): 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;
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/sys/pal/wasm/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
//! The crate itself provides a global allocator which on wasm has no
//! synchronization as there are no threads!

// FIXME(obeis): 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();
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/thread/local/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ fn smoke_dtor() {

#[test]
fn circular() {
// FIXME(obeis): 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ fn issue11371() {
static mut X: Option<i32> = Some(123);
unsafe {
if X.is_some() {
//~^ ERROR: creating a shared reference to mutable static is discouraged
X = None;
X.unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
error: creating a shared reference to mutable static is discouraged
--> tests/ui/checked_unwrap/simple_conditionals.rs:174:12
|
LL | if X.is_some() {
| ^^^^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= 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
= note: `-D static-mut-refs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`

error: called `unwrap` on `x` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/simple_conditionals.rs:46:9
|
Expand Down Expand Up @@ -236,5 +248,5 @@ LL | if result.is_ok() {
LL | result.as_mut().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 25 previous errors
error: aborting due to 26 previous errors

2 changes: 2 additions & 0 deletions src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![allow(unused)]
// FIXME(obeis): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

#[derive(Debug)]
struct Foo;
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![allow(unused)]
// FIXME(obeis): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

#[derive(Debug)]
struct Foo;
Expand Down
36 changes: 18 additions & 18 deletions src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: constants have by default a `'static` lifetime
--> tests/ui/redundant_static_lifetimes.rs:6:17
--> tests/ui/redundant_static_lifetimes.rs:8:17
|
LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static.
| -^^^^^^^---- help: consider removing `'static`: `&str`
Expand All @@ -8,103 +8,103 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removi
= help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]`

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: statics have by default a `'static` lifetime
--> tests/ui/redundant_static_lifetimes.rs:69:16
--> tests/ui/redundant_static_lifetimes.rs:71:16
|
LL | static V: &'static u8 = &17;
| -^^^^^^^--- help: consider removing `'static`: `&u8`
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/tests/ui/useless_conversion.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![deny(clippy::useless_conversion)]
#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
// FIXME(obeis): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

fn test_generic<T: Copy>(val: T) -> T {
let _ = val;
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/tests/ui/useless_conversion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![deny(clippy::useless_conversion)]
#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
// FIXME(obeis): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

fn test_generic<T: Copy>(val: T) -> T {
let _ = T::from(val);
Expand Down
Loading

0 comments on commit 74561dc

Please sign in to comment.