Skip to content

Commit 3b0ce1b

Browse files
committed
Update tests for hidden references to mutable static
1 parent 74cab94 commit 3b0ce1b

File tree

111 files changed

+803
-744
lines changed

Some content is hidden

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

111 files changed

+803
-744
lines changed

library/alloc/src/collections/linked_list/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
2+
#![allow(static_mut_refs)]
3+
14
use std::panic::{catch_unwind, AssertUnwindSafe};
25
use std::thread;
36

library/alloc/src/collections/vec_deque/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
2+
#![allow(static_mut_refs)]
3+
14
use core::iter::TrustedLen;
25

36
use super::*;

library/alloc/tests/fmt.rs

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

35
use std::cell::RefCell;
46
use std::fmt::{self, Write};

library/alloc/tests/vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
2+
#![allow(static_mut_refs)]
3+
14
use core::alloc::{Allocator, Layout};
25
use core::num::NonZero;
36
use core::ptr::NonNull;
@@ -1284,6 +1287,8 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {
12841287

12851288
#[test]
12861289
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
1290+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
1291+
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
12871292
fn test_from_iter_specialization_panic_during_drop_doesnt_leak() {
12881293
static mut DROP_COUNTER_OLD: [usize; 5] = [0; 5];
12891294
static mut DROP_COUNTER_NEW: [usize; 2] = [0; 2];

library/alloc/tests/vec_deque.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
2+
#![allow(static_mut_refs)]
3+
14
use core::num::NonZero;
25
use std::assert_matches::assert_matches;
36
use std::collections::vec_deque::Drain;

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(static_mut_refs): Do not allow `static_mut_refs` 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
@@ -291,6 +291,8 @@ cfg_if::cfg_if! {
291291
}
292292
}
293293

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

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(static_mut_refs): 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/alloc/wasm.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(static_mut_refs): 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(static_mut_refs): 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.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,16 @@ LL | if result.is_ok() {
236236
LL | result.as_mut().unwrap();
237237
| ^^^^^^^^^^^^^^^^^^^^^^^^
238238

239-
error: aborting due to 25 previous errors
239+
error: creating a shared reference to mutable static is discouraged
240+
--> tests/ui/checked_unwrap/simple_conditionals.rs:174:12
241+
|
242+
LL | if X.is_some() {
243+
| ^^^^^^^^^^^ shared reference to mutable static
244+
|
245+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
246+
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
247+
= note: `-D static-mut-refs` implied by `-D warnings`
248+
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`
249+
250+
error: aborting due to 26 previous errors
240251

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(deref_nullptr)]
55
#![allow(clippy::unnecessary_operation)]
66
#![allow(dropping_copy_types)]
7+
#![allow(clippy::assign_op_pattern)]
78
#![warn(clippy::multiple_unsafe_ops_per_block)]
89

910
extern crate proc_macros;

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

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this `unsafe` block contains 2 unsafe operations, expected only one
2-
--> tests/ui/multiple_unsafe_ops_per_block.rs:37:5
2+
--> tests/ui/multiple_unsafe_ops_per_block.rs:38:5
33
|
44
LL | / unsafe {
55
LL | | STATIC += 1;
@@ -8,20 +8,20 @@ LL | | }
88
| |_____^
99
|
1010
note: modification of a mutable static occurs here
11-
--> tests/ui/multiple_unsafe_ops_per_block.rs:38:9
11+
--> tests/ui/multiple_unsafe_ops_per_block.rs:39:9
1212
|
1313
LL | STATIC += 1;
1414
| ^^^^^^^^^^^
1515
note: unsafe function call occurs here
16-
--> tests/ui/multiple_unsafe_ops_per_block.rs:39:9
16+
--> tests/ui/multiple_unsafe_ops_per_block.rs:40:9
1717
|
1818
LL | not_very_safe();
1919
| ^^^^^^^^^^^^^^^
2020
= note: `-D clippy::multiple-unsafe-ops-per-block` implied by `-D warnings`
2121
= help: to override `-D warnings` add `#[allow(clippy::multiple_unsafe_ops_per_block)]`
2222

2323
error: this `unsafe` block contains 2 unsafe operations, expected only one
24-
--> tests/ui/multiple_unsafe_ops_per_block.rs:46:5
24+
--> tests/ui/multiple_unsafe_ops_per_block.rs:47:5
2525
|
2626
LL | / unsafe {
2727
LL | | drop(u.u);
@@ -30,18 +30,18 @@ LL | | }
3030
| |_____^
3131
|
3232
note: union field access occurs here
33-
--> tests/ui/multiple_unsafe_ops_per_block.rs:47:14
33+
--> tests/ui/multiple_unsafe_ops_per_block.rs:48:14
3434
|
3535
LL | drop(u.u);
3636
| ^^^
3737
note: raw pointer dereference occurs here
38-
--> tests/ui/multiple_unsafe_ops_per_block.rs:48:9
38+
--> tests/ui/multiple_unsafe_ops_per_block.rs:49:9
3939
|
4040
LL | *raw_ptr();
4141
| ^^^^^^^^^^
4242

4343
error: this `unsafe` block contains 3 unsafe operations, expected only one
44-
--> tests/ui/multiple_unsafe_ops_per_block.rs:53:5
44+
--> tests/ui/multiple_unsafe_ops_per_block.rs:54:5
4545
|
4646
LL | / unsafe {
4747
LL | | asm!("nop");
@@ -51,23 +51,23 @@ LL | | }
5151
| |_____^
5252
|
5353
note: inline assembly used here
54-
--> tests/ui/multiple_unsafe_ops_per_block.rs:54:9
54+
--> tests/ui/multiple_unsafe_ops_per_block.rs:55:9
5555
|
5656
LL | asm!("nop");
5757
| ^^^^^^^^^^^
5858
note: unsafe method call occurs here
59-
--> tests/ui/multiple_unsafe_ops_per_block.rs:55:9
59+
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:9
6060
|
6161
LL | sample.not_very_safe();
6262
| ^^^^^^^^^^^^^^^^^^^^^^
6363
note: modification of a mutable static occurs here
64-
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:9
64+
--> tests/ui/multiple_unsafe_ops_per_block.rs:57:9
6565
|
6666
LL | STATIC = 0;
6767
| ^^^^^^^^^^
6868

6969
error: this `unsafe` block contains 6 unsafe operations, expected only one
70-
--> tests/ui/multiple_unsafe_ops_per_block.rs:62:5
70+
--> tests/ui/multiple_unsafe_ops_per_block.rs:63:5
7171
|
7272
LL | / unsafe {
7373
LL | | drop(u.u);
@@ -79,55 +79,55 @@ LL | | }
7979
| |_____^
8080
|
8181
note: union field access occurs here
82-
--> tests/ui/multiple_unsafe_ops_per_block.rs:63:14
82+
--> tests/ui/multiple_unsafe_ops_per_block.rs:64:14
8383
|
8484
LL | drop(u.u);
8585
| ^^^
8686
note: access of a mutable static occurs here
87-
--> tests/ui/multiple_unsafe_ops_per_block.rs:64:14
87+
--> tests/ui/multiple_unsafe_ops_per_block.rs:65:14
8888
|
8989
LL | drop(STATIC);
9090
| ^^^^^^
9191
note: unsafe method call occurs here
92-
--> tests/ui/multiple_unsafe_ops_per_block.rs:65:9
92+
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:9
9393
|
9494
LL | sample.not_very_safe();
9595
| ^^^^^^^^^^^^^^^^^^^^^^
9696
note: unsafe function call occurs here
97-
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:9
97+
--> tests/ui/multiple_unsafe_ops_per_block.rs:67:9
9898
|
9999
LL | not_very_safe();
100100
| ^^^^^^^^^^^^^^^
101101
note: raw pointer dereference occurs here
102-
--> tests/ui/multiple_unsafe_ops_per_block.rs:67:9
102+
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:9
103103
|
104104
LL | *raw_ptr();
105105
| ^^^^^^^^^^
106106
note: inline assembly used here
107-
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:9
107+
--> tests/ui/multiple_unsafe_ops_per_block.rs:69:9
108108
|
109109
LL | asm!("nop");
110110
| ^^^^^^^^^^^
111111

112112
error: this `unsafe` block contains 2 unsafe operations, expected only one
113-
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:5
113+
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:5
114114
|
115115
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
116116
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117117
|
118118
note: unsafe function call occurs here
119-
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:14
119+
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:14
120120
|
121121
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
122122
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123123
note: raw pointer dereference occurs here
124-
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:39
124+
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:39
125125
|
126126
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
127127
| ^^^^^^^^^^^^^^^^^^
128128

129129
error: this `unsafe` block contains 2 unsafe operations, expected only one
130-
--> tests/ui/multiple_unsafe_ops_per_block.rs:124:5
130+
--> tests/ui/multiple_unsafe_ops_per_block.rs:125:5
131131
|
132132
LL | / unsafe {
133133
LL | | x();
@@ -136,18 +136,18 @@ LL | | }
136136
| |_____^
137137
|
138138
note: unsafe function call occurs here
139-
--> tests/ui/multiple_unsafe_ops_per_block.rs:125:9
139+
--> tests/ui/multiple_unsafe_ops_per_block.rs:126:9
140140
|
141141
LL | x();
142142
| ^^^
143143
note: unsafe function call occurs here
144-
--> tests/ui/multiple_unsafe_ops_per_block.rs:126:9
144+
--> tests/ui/multiple_unsafe_ops_per_block.rs:127:9
145145
|
146146
LL | x();
147147
| ^^^
148148

149149
error: this `unsafe` block contains 2 unsafe operations, expected only one
150-
--> tests/ui/multiple_unsafe_ops_per_block.rs:135:9
150+
--> tests/ui/multiple_unsafe_ops_per_block.rs:136:9
151151
|
152152
LL | / unsafe {
153153
LL | | T::X();
@@ -156,18 +156,18 @@ LL | | }
156156
| |_________^
157157
|
158158
note: unsafe function call occurs here
159-
--> tests/ui/multiple_unsafe_ops_per_block.rs:136:13
159+
--> tests/ui/multiple_unsafe_ops_per_block.rs:137:13
160160
|
161161
LL | T::X();
162162
| ^^^^^^
163163
note: unsafe function call occurs here
164-
--> tests/ui/multiple_unsafe_ops_per_block.rs:137:13
164+
--> tests/ui/multiple_unsafe_ops_per_block.rs:138:13
165165
|
166166
LL | T::X();
167167
| ^^^^^^
168168

169169
error: this `unsafe` block contains 2 unsafe operations, expected only one
170-
--> tests/ui/multiple_unsafe_ops_per_block.rs:145:5
170+
--> tests/ui/multiple_unsafe_ops_per_block.rs:146:5
171171
|
172172
LL | / unsafe {
173173
LL | | x.0();
@@ -176,12 +176,12 @@ LL | | }
176176
| |_____^
177177
|
178178
note: unsafe function call occurs here
179-
--> tests/ui/multiple_unsafe_ops_per_block.rs:146:9
179+
--> tests/ui/multiple_unsafe_ops_per_block.rs:147:9
180180
|
181181
LL | x.0();
182182
| ^^^^^
183183
note: unsafe function call occurs here
184-
--> tests/ui/multiple_unsafe_ops_per_block.rs:147:9
184+
--> tests/ui/multiple_unsafe_ops_per_block.rs:148:9
185185
|
186186
LL | x.0();
187187
| ^^^^^

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![feature(never_type)]
2-
#![allow(unused_mut, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut)]
2+
#![allow(
3+
unused_mut,
4+
clippy::redundant_allocation,
5+
clippy::needless_pass_by_ref_mut,
6+
static_mut_refs
7+
)]
38
#![warn(clippy::must_use_candidate)]
49
use std::rc::Rc;
510
use std::sync::atomic::{AtomicBool, Ordering};

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![feature(never_type)]
2-
#![allow(unused_mut, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut)]
2+
#![allow(
3+
unused_mut,
4+
clippy::redundant_allocation,
5+
clippy::needless_pass_by_ref_mut,
6+
static_mut_refs
7+
)]
38
#![warn(clippy::must_use_candidate)]
49
use std::rc::Rc;
510
use std::sync::atomic::{AtomicBool, Ordering};

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this function could have a `#[must_use]` attribute
2-
--> tests/ui/must_use_candidates.rs:11:1
2+
--> tests/ui/must_use_candidates.rs:16:1
33
|
44
LL | pub fn pure(i: u8) -> u8 {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8`
@@ -8,25 +8,25 @@ LL | pub fn pure(i: u8) -> u8 {
88
= help: to override `-D warnings` add `#[allow(clippy::must_use_candidate)]`
99

1010
error: this method could have a `#[must_use]` attribute
11-
--> tests/ui/must_use_candidates.rs:16:5
11+
--> tests/ui/must_use_candidates.rs:21:5
1212
|
1313
LL | pub fn inherent_pure(&self) -> u8 {
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8`
1515

1616
error: this function could have a `#[must_use]` attribute
17-
--> tests/ui/must_use_candidates.rs:47:1
17+
--> tests/ui/must_use_candidates.rs:52:1
1818
|
1919
LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool {
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool`
2121

2222
error: this function could have a `#[must_use]` attribute
23-
--> tests/ui/must_use_candidates.rs:59:1
23+
--> tests/ui/must_use_candidates.rs:64:1
2424
|
2525
LL | pub fn rcd(_x: Rc<u32>) -> bool {
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc<u32>) -> bool`
2727

2828
error: this function could have a `#[must_use]` attribute
29-
--> tests/ui/must_use_candidates.rs:67:1
29+
--> tests/ui/must_use_candidates.rs:72:1
3030
|
3131
LL | pub fn arcd(_x: Arc<u32>) -> bool {
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`

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(static_mut_refs): 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(static_mut_refs): Do not allow `static_mut_refs` lint
3+
#![allow(static_mut_refs)]
24

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

0 commit comments

Comments
 (0)