Skip to content

Commit

Permalink
Auto merge of rust-lang#124895 - obeis:static-mut-hidden-ref, r=compi…
Browse files Browse the repository at this point in the history
…ler-errors

Disallow hidden references to mutable static

Closes rust-lang#123060

Tracking:
- rust-lang#123758
  • Loading branch information
bors committed Sep 20, 2024
2 parents 4f31900 + cd99729 commit bb04c68
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 92 deletions.
13 changes: 12 additions & 1 deletion tests/ui/checked_unwrap/simple_conditionals.stderr
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 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 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 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 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 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 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 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 bb04c68

Please sign in to comment.