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 Sep 13, 2024
1 parent 74cab94 commit 3b0ce1b
Show file tree
Hide file tree
Showing 111 changed files with 803 additions and 744 deletions.
3 changes: 3 additions & 0 deletions library/alloc/src/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::panic::{catch_unwind, AssertUnwindSafe};
use std::thread;

Expand Down
3 changes: 3 additions & 0 deletions library/alloc/src/collections/vec_deque/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use core::iter::TrustedLen;

use super::*;
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/tests/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![deny(warnings)]
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use std::cell::RefCell;
use std::fmt::{self, Write};
Expand Down
5 changes: 5 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use core::alloc::{Allocator, Layout};
use core::num::NonZero;
use core::ptr::NonNull;
Expand Down Expand Up @@ -1284,6 +1287,8 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {

#[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
// FIXME(static_mut_refs): Do not allow `static_mut_refs` 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
3 changes: 3 additions & 0 deletions library/alloc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use core::num::NonZero;
use std::assert_matches::assert_matches;
use std::collections::vec_deque::Drain;
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(static_mut_refs): Do not allow `static_mut_refs` 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 @@ -291,6 +291,8 @@ cfg_if::cfg_if! {
}
}

// FIXME(static_mut_refs): 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(static_mut_refs): 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/alloc/wasm.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(static_mut_refs): 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(static_mut_refs): 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 @@ -236,5 +236,16 @@ LL | if result.is_ok() {
LL | result.as_mut().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 25 previous errors
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 <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
= 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
= note: `-D static-mut-refs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`

error: aborting due to 26 previous errors

1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![allow(deref_nullptr)]
#![allow(clippy::unnecessary_operation)]
#![allow(dropping_copy_types)]
#![allow(clippy::assign_op_pattern)]
#![warn(clippy::multiple_unsafe_ops_per_block)]

extern crate proc_macros;
Expand Down
58 changes: 29 additions & 29 deletions src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this `unsafe` block contains 2 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:37:5
--> tests/ui/multiple_unsafe_ops_per_block.rs:38:5
|
LL | / unsafe {
LL | | STATIC += 1;
Expand All @@ -8,20 +8,20 @@ LL | | }
| |_____^
|
note: modification of a mutable static occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:38:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:39:9
|
LL | STATIC += 1;
| ^^^^^^^^^^^
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:39:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:40:9
|
LL | not_very_safe();
| ^^^^^^^^^^^^^^^
= note: `-D clippy::multiple-unsafe-ops-per-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::multiple_unsafe_ops_per_block)]`

error: this `unsafe` block contains 2 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:46:5
--> tests/ui/multiple_unsafe_ops_per_block.rs:47:5
|
LL | / unsafe {
LL | | drop(u.u);
Expand All @@ -30,18 +30,18 @@ LL | | }
| |_____^
|
note: union field access occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:47:14
--> tests/ui/multiple_unsafe_ops_per_block.rs:48:14
|
LL | drop(u.u);
| ^^^
note: raw pointer dereference occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:48:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:49:9
|
LL | *raw_ptr();
| ^^^^^^^^^^

error: this `unsafe` block contains 3 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:53:5
--> tests/ui/multiple_unsafe_ops_per_block.rs:54:5
|
LL | / unsafe {
LL | | asm!("nop");
Expand All @@ -51,23 +51,23 @@ LL | | }
| |_____^
|
note: inline assembly used here
--> tests/ui/multiple_unsafe_ops_per_block.rs:54:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:55:9
|
LL | asm!("nop");
| ^^^^^^^^^^^
note: unsafe method call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:55:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:9
|
LL | sample.not_very_safe();
| ^^^^^^^^^^^^^^^^^^^^^^
note: modification of a mutable static occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:57:9
|
LL | STATIC = 0;
| ^^^^^^^^^^

error: this `unsafe` block contains 6 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:62:5
--> tests/ui/multiple_unsafe_ops_per_block.rs:63:5
|
LL | / unsafe {
LL | | drop(u.u);
Expand All @@ -79,55 +79,55 @@ LL | | }
| |_____^
|
note: union field access occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:63:14
--> tests/ui/multiple_unsafe_ops_per_block.rs:64:14
|
LL | drop(u.u);
| ^^^
note: access of a mutable static occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:64:14
--> tests/ui/multiple_unsafe_ops_per_block.rs:65:14
|
LL | drop(STATIC);
| ^^^^^^
note: unsafe method call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:65:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:9
|
LL | sample.not_very_safe();
| ^^^^^^^^^^^^^^^^^^^^^^
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:67:9
|
LL | not_very_safe();
| ^^^^^^^^^^^^^^^
note: raw pointer dereference occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:67:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:9
|
LL | *raw_ptr();
| ^^^^^^^^^^
note: inline assembly used here
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:69:9
|
LL | asm!("nop");
| ^^^^^^^^^^^

error: this `unsafe` block contains 2 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:5
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:5
|
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:14
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:14
|
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: raw pointer dereference occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:39
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:39
|
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
| ^^^^^^^^^^^^^^^^^^

error: this `unsafe` block contains 2 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:124:5
--> tests/ui/multiple_unsafe_ops_per_block.rs:125:5
|
LL | / unsafe {
LL | | x();
Expand All @@ -136,18 +136,18 @@ LL | | }
| |_____^
|
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:125:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:126:9
|
LL | x();
| ^^^
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:126:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:127:9
|
LL | x();
| ^^^

error: this `unsafe` block contains 2 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:135:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:136:9
|
LL | / unsafe {
LL | | T::X();
Expand All @@ -156,18 +156,18 @@ LL | | }
| |_________^
|
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:136:13
--> tests/ui/multiple_unsafe_ops_per_block.rs:137:13
|
LL | T::X();
| ^^^^^^
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:137:13
--> tests/ui/multiple_unsafe_ops_per_block.rs:138:13
|
LL | T::X();
| ^^^^^^

error: this `unsafe` block contains 2 unsafe operations, expected only one
--> tests/ui/multiple_unsafe_ops_per_block.rs:145:5
--> tests/ui/multiple_unsafe_ops_per_block.rs:146:5
|
LL | / unsafe {
LL | | x.0();
Expand All @@ -176,12 +176,12 @@ LL | | }
| |_____^
|
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:146:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:147:9
|
LL | x.0();
| ^^^^^
note: unsafe function call occurs here
--> tests/ui/multiple_unsafe_ops_per_block.rs:147:9
--> tests/ui/multiple_unsafe_ops_per_block.rs:148:9
|
LL | x.0();
| ^^^^^
Expand Down
7 changes: 6 additions & 1 deletion src/tools/clippy/tests/ui/must_use_candidates.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![feature(never_type)]
#![allow(unused_mut, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut)]
#![allow(
unused_mut,
clippy::redundant_allocation,
clippy::needless_pass_by_ref_mut,
static_mut_refs
)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down
7 changes: 6 additions & 1 deletion src/tools/clippy/tests/ui/must_use_candidates.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![feature(never_type)]
#![allow(unused_mut, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut)]
#![allow(
unused_mut,
clippy::redundant_allocation,
clippy::needless_pass_by_ref_mut,
static_mut_refs
)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down
10 changes: 5 additions & 5 deletions src/tools/clippy/tests/ui/must_use_candidates.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this function could have a `#[must_use]` attribute
--> tests/ui/must_use_candidates.rs:11:1
--> tests/ui/must_use_candidates.rs:16:1
|
LL | pub fn pure(i: u8) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8`
Expand All @@ -8,25 +8,25 @@ LL | pub fn pure(i: u8) -> u8 {
= help: to override `-D warnings` add `#[allow(clippy::must_use_candidate)]`

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

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

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

error: this function could have a `#[must_use]` attribute
--> tests/ui/must_use_candidates.rs:67:1
--> tests/ui/must_use_candidates.rs:72:1
|
LL | pub fn arcd(_x: Arc<u32>) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`
Expand Down
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(static_mut_refs): 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(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

#[derive(Debug)]
struct Foo;
Expand Down
Loading

0 comments on commit 3b0ce1b

Please sign in to comment.