Skip to content

Commit

Permalink
Update UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
obeis committed May 8, 2024
1 parent d97f0a1 commit 968dfbc
Show file tree
Hide file tree
Showing 28 changed files with 309 additions and 15 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_driver_impl/src/signal_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ macro raw_errln($tokens:tt) {
}

/// Signal handler installed for SIGSEGV
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
#[allow(static_mut_refs)]
extern "C" fn print_stack_trace(_: libc::c_int) {
const MAX_FRAMES: usize = 256;
// Reserve data segment so we don't have to malloc in a signal handler, which might fail
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,6 @@ ui/issues/issue-17068.rs
ui/issues/issue-17121.rs
ui/issues/issue-17216.rs
ui/issues/issue-17252.rs
ui/issues/issue-17302.rs
ui/issues/issue-17322.rs
ui/issues/issue-17336.rs
ui/issues/issue-17337.rs
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/async-await/issues/issue-67611-static-mut-refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn is_send_sync<T: Send + Sync>(_: T) {}

async fn fun() {
let u = unsafe { A[async { 1 }.await] };
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
unsafe {
match A {
i if async { true }.await => (),
Expand All @@ -21,6 +22,7 @@ async fn fun() {
fn main() {
let index_block = async {
let u = unsafe { A[async { 1 }.await] };
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
};
let match_block = async {
unsafe {
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/async-await/issues/issue-67611-static-mut-refs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-67611-static-mut-refs.rs:11:22
|
LL | let u = unsafe { A[async { 1 }.await] };
| ^^^^^^^^^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-67611-static-mut-refs.rs:24:26
|
LL | let u = unsafe { A[async { 1 }.await] };
| ^^^^^^^^^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

warning: 2 warnings emitted

3 changes: 3 additions & 0 deletions tests/ui/binding/order-drop-with-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl Drop for A {
fn drop(&mut self) {
unsafe {
ORDER[INDEX] = 1;
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
INDEX = INDEX + 1;
}
}
Expand All @@ -24,6 +25,7 @@ impl Drop for B {
fn drop(&mut self) {
unsafe {
ORDER[INDEX] = 2;
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
INDEX = INDEX + 1;
}
}
Expand All @@ -34,6 +36,7 @@ impl Drop for C {
fn drop(&mut self) {
unsafe {
ORDER[INDEX] = 3;
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
INDEX = INDEX + 1;
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/ui/binding/order-drop-with-match.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/order-drop-with-match.rs:16:13
|
LL | ORDER[INDEX] = 1;
| ^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: creating a shared reference to mutable static is discouraged
--> $DIR/order-drop-with-match.rs:27:13
|
LL | ORDER[INDEX] = 2;
| ^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

warning: creating a shared reference to mutable static is discouraged
--> $DIR/order-drop-with-match.rs:38:13
|
LL | ORDER[INDEX] = 3;
| ^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

warning: 3 warnings emitted

2 changes: 2 additions & 0 deletions tests/ui/consts/static-mut-refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ static mut INT_RAW: *mut isize = &mut 1isize as *mut _;
pub fn main() {
unsafe {
TEST[0] += 1;
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
assert_eq!(TEST[0], 2);
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
*INT_RAW += 1;
assert_eq!(*INT_RAW, 2);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/consts/static-mut-refs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/static-mut-refs.rs:19:9
|
LL | TEST[0] += 1;
| ^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: creating a shared reference to mutable static is discouraged
--> $DIR/static-mut-refs.rs:21:20
|
LL | assert_eq!(TEST[0], 2);
| ^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

warning: 2 warnings emitted

2 changes: 1 addition & 1 deletion tests/ui/coroutine/static-mut-reference-across-yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
unsafe {
let gen_index = #[coroutine]
static || {
let u = A[{
let u = A[{ //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
yield;
1
}];
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/coroutine/static-mut-reference-across-yield.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/static-mut-reference-across-yield.rs:13:21
|
LL | let u = A[{
| _____________________^
LL | | yield;
LL | | 1
LL | | }];
| |______________^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/drop/issue-23338-ensure-param-drop-order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub mod d {
pub type Log<'a> = &'a RefCell<Vec<u32>>;

pub fn current_width() -> u32 {
unsafe { max_width() - trails.leading_zeros() }
unsafe { max_width() - trails.leading_zeros() } //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
}

pub fn max_width() -> u32 {
Expand Down
14 changes: 12 additions & 2 deletions tests/ui/drop/issue-23338-ensure-param-drop-order.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-23338-ensure-param-drop-order.rs:88:32
|
LL | ... unsafe { max_width() - trails.leading_zeros() }
| ^^^^^^^^^^^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-23338-ensure-param-drop-order.rs:93:31
|
Expand All @@ -7,11 +18,10 @@ LL | (mem::size_of_val(&trails) * 8) as u32
= 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default
help: use `addr_of!` instead to create a raw pointer
|
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
| ~~~~~~~~~~~~~~~~

warning: 1 warning emitted
warning: 2 warnings emitted

2 changes: 1 addition & 1 deletion tests/ui/drop/issue-23611-enum-swap-in-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub mod d {
pub type Log<'a> = &'a RefCell<Vec<u32>>;

pub fn current_width() -> u32 {
unsafe { max_width() - trails.leading_zeros() }
unsafe { max_width() - trails.leading_zeros() } //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
}

pub fn max_width() -> u32 {
Expand Down
14 changes: 12 additions & 2 deletions tests/ui/drop/issue-23611-enum-swap-in-drop.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-23611-enum-swap-in-drop.rs:184:32
|
LL | ... unsafe { max_width() - trails.leading_zeros() }
| ^^^^^^^^^^^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-23611-enum-swap-in-drop.rs:189:31
|
Expand All @@ -7,11 +18,10 @@ LL | (mem::size_of_val(&trails) * 8) as u32
= 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default
help: use `addr_of!` instead to create a raw pointer
|
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
| ~~~~~~~~~~~~~~~~

warning: 1 warning emitted
warning: 2 warnings emitted

2 changes: 2 additions & 0 deletions tests/ui/drop/issue-48962.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl Drop for Dropee {
fn drop(&mut self) {
unsafe {
ORDER[INDEX] = self.0;
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
INDEX = INDEX + 1;
}
}
Expand All @@ -18,6 +19,7 @@ impl Drop for Dropee {
fn add_sentintel() {
unsafe {
ORDER[INDEX] = 2;
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
INDEX = INDEX + 1;
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/drop/issue-48962.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-48962.rs:12:13
|
LL | ORDER[INDEX] = self.0;
| ^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-48962.rs:21:9
|
LL | ORDER[INDEX] = 2;
| ^^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

warning: 2 warnings emitted

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl Drop for A {
fn drop(&mut self) {
let A(i) = *self;
unsafe { DROPPED[i] = true; }
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
}
}

Expand All @@ -21,6 +22,8 @@ fn main() {
}
unsafe {
assert!(DROPPED[0]);
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
assert!(DROPPED[1]);
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
}
}
33 changes: 33 additions & 0 deletions tests/ui/drop/static-issue-17302.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/static-issue-17302.rs:11:18
|
LL | unsafe { DROPPED[i] = true; }
| ^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: creating a shared reference to mutable static is discouraged
--> $DIR/static-issue-17302.rs:24:17
|
LL | assert!(DROPPED[0]);
| ^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

warning: creating a shared reference to mutable static is discouraged
--> $DIR/static-issue-17302.rs:26:17
|
LL | assert!(DROPPED[1]);
| ^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

warning: 3 warnings emitted

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod foo {

pub fn make_secrets(a: u8, b: String) -> S {
let val = unsafe { let p = COUNT.get(); let val = *p; *p = val + 1; val };
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
println!("creating {}, uid {}", b, val);
S { a: a, b: b, secret_uid: val }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/functional-struct-update-respects-privacy.rs:14:36
|
LL | let val = unsafe { let p = COUNT.get(); let val = *p; *p = val + 1; val };
| ^^^^^^^^^^^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

error[E0451]: field `secret_uid` of struct `S` is private
--> $DIR/functional-struct-update-respects-privacy.rs:28:49
--> $DIR/functional-struct-update-respects-privacy.rs:29:49
|
LL | let s_2 = foo::S { b: format!("ess two"), ..s_1 }; // FRU ...
| ^^^ field `secret_uid` is private

error: aborting due to 1 previous error
error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0451`.
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-39367.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn arena() -> &'static ArenaSet<Vec<u8>> {
static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();

static mut ONCE: Once = Once::new();
ONCE.call_once(|| {
ONCE.call_once(|| { //~ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
DATA = transmute
::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
(Box::new(__static_ref_initialize()));
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/issues/issue-39367.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
warning: creating a shared reference to mutable static is discouraged
--> $DIR/issue-39367.rs:22:13
|
LL | / ONCE.call_once(|| {
LL | | DATA = transmute
LL | | ::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
LL | | (Box::new(__static_ref_initialize()));
LL | | });
| |______________^ 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: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `#[warn(static_mut_refs)]` on by default

warning: 1 warning emitted

Loading

0 comments on commit 968dfbc

Please sign in to comment.