From 7d2fd98087a1326282c45162d92de2f90db91a8a Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Wed, 8 May 2024 18:03:45 +0300 Subject: [PATCH] Update test --- .../rustc_driver_impl/src/signal_handler.rs | 2 ++ library/alloc/tests/vec.rs | 2 ++ library/core/tests/atomic.rs | 2 ++ src/tools/tidy/src/issues.txt | 1 - .../issues/issue-67611-static-mut-refs.rs | 2 ++ .../issues/issue-67611-static-mut-refs.stderr | 23 +++++++++++++ tests/ui/binding/order-drop-with-match.rs | 3 ++ tests/ui/binding/order-drop-with-match.stderr | 33 +++++++++++++++++++ tests/ui/consts/static-mut-refs.rs | 2 ++ tests/ui/consts/static-mut-refs.stderr | 23 +++++++++++++ .../static-mut-reference-across-yield.rs | 2 +- .../static-mut-reference-across-yield.stderr | 17 ++++++++++ .../issue-23338-ensure-param-drop-order.rs | 2 +- ...issue-23338-ensure-param-drop-order.stderr | 14 ++++++-- .../ui/drop/issue-23611-enum-swap-in-drop.rs | 2 +- .../drop/issue-23611-enum-swap-in-drop.stderr | 14 ++++++-- tests/ui/drop/issue-48962.rs | 2 ++ tests/ui/drop/issue-48962.stderr | 23 +++++++++++++ .../static-issue-17302.rs} | 3 ++ tests/ui/drop/static-issue-17302.stderr | 33 +++++++++++++++++++ ...nctional-struct-update-respects-privacy.rs | 1 + ...onal-struct-update-respects-privacy.stderr | 15 +++++++-- tests/ui/issues/issue-39367.rs | 2 +- tests/ui/issues/issue-39367.stderr | 17 ++++++++++ .../reference-of-mut-static.e2021.stderr | 22 ++++++++++++- .../reference-of-mut-static.e2024.stderr | 18 +++++++++- tests/ui/static/reference-of-mut-static.rs | 4 +++ .../reference-to-mut-static.e2021.stderr | 22 ++++++++++++- .../reference-to-mut-static.e2024.stderr | 18 +++++++++- tests/ui/static/reference-to-mut-static.rs | 4 +++ 30 files changed, 313 insertions(+), 15 deletions(-) create mode 100644 tests/ui/async-await/issues/issue-67611-static-mut-refs.stderr create mode 100644 tests/ui/binding/order-drop-with-match.stderr create mode 100644 tests/ui/consts/static-mut-refs.stderr create mode 100644 tests/ui/coroutine/static-mut-reference-across-yield.stderr create mode 100644 tests/ui/drop/issue-48962.stderr rename tests/ui/{issues/issue-17302.rs => drop/static-issue-17302.rs} (58%) create mode 100644 tests/ui/drop/static-issue-17302.stderr create mode 100644 tests/ui/issues/issue-39367.stderr diff --git a/compiler/rustc_driver_impl/src/signal_handler.rs b/compiler/rustc_driver_impl/src/signal_handler.rs index 441219eec90dc..1a3ad78cefd04 100644 --- a/compiler/rustc_driver_impl/src/signal_handler.rs +++ b/compiler/rustc_driver_impl/src/signal_handler.rs @@ -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 diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 71d79893e01d7..8a0a95f20e452 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -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]; diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs index 0d1c72a689291..d6874fb25e411 100644 --- a/library/core/tests/atomic.rs +++ b/library/core/tests/atomic.rs @@ -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); diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index a931782e8ccbe..911fd67e521c4 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -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 diff --git a/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs b/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs index 51e85931dbf20..38b42ccb8b2ef 100644 --- a/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs +++ b/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs @@ -9,6 +9,7 @@ fn is_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 => (), @@ -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 { diff --git a/tests/ui/async-await/issues/issue-67611-static-mut-refs.stderr b/tests/ui/async-await/issues/issue-67611-static-mut-refs.stderr new file mode 100644 index 0000000000000..1dffe8c2e7c36 --- /dev/null +++ b/tests/ui/async-await/issues/issue-67611-static-mut-refs.stderr @@ -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 + = 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 + = 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 + diff --git a/tests/ui/binding/order-drop-with-match.rs b/tests/ui/binding/order-drop-with-match.rs index c12c5e4c62779..8ab31b827ef1c 100644 --- a/tests/ui/binding/order-drop-with-match.rs +++ b/tests/ui/binding/order-drop-with-match.rs @@ -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; } } @@ -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; } } @@ -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; } } diff --git a/tests/ui/binding/order-drop-with-match.stderr b/tests/ui/binding/order-drop-with-match.stderr new file mode 100644 index 0000000000000..ad972b545e885 --- /dev/null +++ b/tests/ui/binding/order-drop-with-match.stderr @@ -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 + = 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 + = 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 + = 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 + diff --git a/tests/ui/consts/static-mut-refs.rs b/tests/ui/consts/static-mut-refs.rs index d4ebfbbf17a86..903ca9baa2543 100644 --- a/tests/ui/consts/static-mut-refs.rs +++ b/tests/ui/consts/static-mut-refs.rs @@ -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); } diff --git a/tests/ui/consts/static-mut-refs.stderr b/tests/ui/consts/static-mut-refs.stderr new file mode 100644 index 0000000000000..539de593f2dd4 --- /dev/null +++ b/tests/ui/consts/static-mut-refs.stderr @@ -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 + = 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 + = 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 + diff --git a/tests/ui/coroutine/static-mut-reference-across-yield.rs b/tests/ui/coroutine/static-mut-reference-across-yield.rs index 40d5fdf2d5736..7350fc0a14adc 100644 --- a/tests/ui/coroutine/static-mut-reference-across-yield.rs +++ b/tests/ui/coroutine/static-mut-reference-across-yield.rs @@ -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 }]; diff --git a/tests/ui/coroutine/static-mut-reference-across-yield.stderr b/tests/ui/coroutine/static-mut-reference-across-yield.stderr new file mode 100644 index 0000000000000..23bb81fc4bd0c --- /dev/null +++ b/tests/ui/coroutine/static-mut-reference-across-yield.stderr @@ -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 + = 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 + diff --git a/tests/ui/drop/issue-23338-ensure-param-drop-order.rs b/tests/ui/drop/issue-23338-ensure-param-drop-order.rs index 1fa68a2e73813..283c6ae128639 100644 --- a/tests/ui/drop/issue-23338-ensure-param-drop-order.rs +++ b/tests/ui/drop/issue-23338-ensure-param-drop-order.rs @@ -85,7 +85,7 @@ pub mod d { pub type Log<'a> = &'a RefCell>; 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 { diff --git a/tests/ui/drop/issue-23338-ensure-param-drop-order.stderr b/tests/ui/drop/issue-23338-ensure-param-drop-order.stderr index de1194e74b40d..0e1eaf1996f0c 100644 --- a/tests/ui/drop/issue-23338-ensure-param-drop-order.stderr +++ b/tests/ui/drop/issue-23338-ensure-param-drop-order.stderr @@ -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 + = 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 | @@ -7,11 +18,10 @@ LL | (mem::size_of_val(&trails) * 8) as u32 = note: for more information, see issue #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 diff --git a/tests/ui/drop/issue-23611-enum-swap-in-drop.rs b/tests/ui/drop/issue-23611-enum-swap-in-drop.rs index 1afaff0f735be..8745d7d60d6c0 100644 --- a/tests/ui/drop/issue-23611-enum-swap-in-drop.rs +++ b/tests/ui/drop/issue-23611-enum-swap-in-drop.rs @@ -181,7 +181,7 @@ pub mod d { pub type Log<'a> = &'a RefCell>; 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 { diff --git a/tests/ui/drop/issue-23611-enum-swap-in-drop.stderr b/tests/ui/drop/issue-23611-enum-swap-in-drop.stderr index bdf46abea8a1f..d9d784e6a7a40 100644 --- a/tests/ui/drop/issue-23611-enum-swap-in-drop.stderr +++ b/tests/ui/drop/issue-23611-enum-swap-in-drop.stderr @@ -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 + = 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 | @@ -7,11 +18,10 @@ LL | (mem::size_of_val(&trails) * 8) as u32 = note: for more information, see issue #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 diff --git a/tests/ui/drop/issue-48962.rs b/tests/ui/drop/issue-48962.rs index 428a6ca6cd21b..90aac51697184 100644 --- a/tests/ui/drop/issue-48962.rs +++ b/tests/ui/drop/issue-48962.rs @@ -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; } } @@ -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; } } diff --git a/tests/ui/drop/issue-48962.stderr b/tests/ui/drop/issue-48962.stderr new file mode 100644 index 0000000000000..57ee000c9444f --- /dev/null +++ b/tests/ui/drop/issue-48962.stderr @@ -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 + = 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 + = 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 + diff --git a/tests/ui/issues/issue-17302.rs b/tests/ui/drop/static-issue-17302.rs similarity index 58% rename from tests/ui/issues/issue-17302.rs rename to tests/ui/drop/static-issue-17302.rs index c499cc5281f3a..9f5ad9b49781a 100644 --- a/tests/ui/issues/issue-17302.rs +++ b/tests/ui/drop/static-issue-17302.rs @@ -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] } } @@ -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] } } diff --git a/tests/ui/drop/static-issue-17302.stderr b/tests/ui/drop/static-issue-17302.stderr new file mode 100644 index 0000000000000..c9631bc84daf2 --- /dev/null +++ b/tests/ui/drop/static-issue-17302.stderr @@ -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 + = 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 + = 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 + = 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 + diff --git a/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.rs b/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.rs index 500633edf12de..16d467ccdcea0 100644 --- a/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.rs +++ b/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.rs @@ -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 } } diff --git a/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.stderr b/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.stderr index 692d98bc53c82..eb71f88b17cce 100644 --- a/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.stderr +++ b/tests/ui/functional-struct-update/functional-struct-update-respects-privacy.stderr @@ -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 + = 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`. diff --git a/tests/ui/issues/issue-39367.rs b/tests/ui/issues/issue-39367.rs index dd16d4da1bdd2..4a28bd80f234a 100644 --- a/tests/ui/issues/issue-39367.rs +++ b/tests/ui/issues/issue-39367.rs @@ -19,7 +19,7 @@ fn arena() -> &'static ArenaSet> { static mut DATA: *const ArenaSet> = 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 ::>>, *const ArenaSet>> (Box::new(__static_ref_initialize())); diff --git a/tests/ui/issues/issue-39367.stderr b/tests/ui/issues/issue-39367.stderr new file mode 100644 index 0000000000000..f0c82bc97e559 --- /dev/null +++ b/tests/ui/issues/issue-39367.stderr @@ -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 | | ::>>, *const ArenaSet>> +LL | | (Box::new(__static_ref_initialize())); +LL | | }); + | |______________^ shared reference to mutable static + | + = note: for more information, see issue #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 + diff --git a/tests/ui/static/reference-of-mut-static.e2021.stderr b/tests/ui/static/reference-of-mut-static.e2021.stderr index f7ad51b615711..a411185ecb7ce 100644 --- a/tests/ui/static/reference-of-mut-static.e2021.stderr +++ b/tests/ui/static/reference-of-mut-static.e2021.stderr @@ -87,5 +87,25 @@ help: use `addr_of!` instead to create a raw pointer LL | foo(addr_of!(X)); | ~~~~~~~~~~~ -error: aborting due to 6 previous errors +error: creating a shared reference to mutable static is discouraged + --> $DIR/reference-of-mut-static.rs:44:17 + | +LL | let _ = Z.len(); + | ^^^^^^^ shared reference to mutable static + | + = note: for more information, see issue #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 + +error: creating a shared reference to mutable static is discouraged + --> $DIR/reference-of-mut-static.rs:47:17 + | +LL | let _ = Z[0]; + | ^^^^ shared reference to mutable static + | + = note: for more information, see issue #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 + +error: aborting due to 8 previous errors diff --git a/tests/ui/static/reference-of-mut-static.e2024.stderr b/tests/ui/static/reference-of-mut-static.e2024.stderr index 6205c10ac416f..85fb5e659244c 100644 --- a/tests/ui/static/reference-of-mut-static.e2024.stderr +++ b/tests/ui/static/reference-of-mut-static.e2024.stderr @@ -70,6 +70,22 @@ help: use `addr_of!` instead to create a raw pointer LL | foo(addr_of!(X)); | ~~~~~~~~~~~ -error: aborting due to 6 previous errors +error[E0796]: creating a shared reference to a mutable static + --> $DIR/reference-of-mut-static.rs:44:17 + | +LL | let _ = Z.len(); + | ^^^^^^^ shared reference to mutable static + | + = 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 + +error[E0796]: creating a shared reference to a mutable static + --> $DIR/reference-of-mut-static.rs:47:17 + | +LL | let _ = Z[0]; + | ^^^^ shared reference to mutable static + | + = 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 + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0796`. diff --git a/tests/ui/static/reference-of-mut-static.rs b/tests/ui/static/reference-of-mut-static.rs index af2cab7dd8723..71a81cc414444 100644 --- a/tests/ui/static/reference-of-mut-static.rs +++ b/tests/ui/static/reference-of-mut-static.rs @@ -42,7 +42,11 @@ fn main() { static mut Z: &[i32; 3] = &[0, 1, 2]; let _ = Z.len(); + //[e2024]~^ creating a shared reference to a mutable static [E0796] + //[e2021]~^^ creating a shared reference to mutable static is discouraged [static_mut_refs] let _ = Z[0]; + //[e2024]~^ creating a shared reference to a mutable static [E0796] + //[e2021]~^^ creating a shared reference to mutable static is discouraged [static_mut_refs] let _ = format!("{:?}", Z); } } diff --git a/tests/ui/static/reference-to-mut-static.e2021.stderr b/tests/ui/static/reference-to-mut-static.e2021.stderr index f477e5ac6c5c2..b3b49c1f5d8e3 100644 --- a/tests/ui/static/reference-to-mut-static.e2021.stderr +++ b/tests/ui/static/reference-to-mut-static.e2021.stderr @@ -87,5 +87,25 @@ help: use `addr_of!` instead to create a raw pointer LL | foo(addr_of!(X)); | ~~~~~~~~~~~ -error: aborting due to 6 previous errors +error: creating a shared reference to mutable static is discouraged + --> $DIR/reference-to-mut-static.rs:44:17 + | +LL | let _ = Z.len(); + | ^^^^^^^ shared reference to mutable static + | + = note: for more information, see issue #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 + +error: creating a shared reference to mutable static is discouraged + --> $DIR/reference-to-mut-static.rs:47:17 + | +LL | let _ = Z[0]; + | ^^^^ shared reference to mutable static + | + = note: for more information, see issue #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 + +error: aborting due to 8 previous errors diff --git a/tests/ui/static/reference-to-mut-static.e2024.stderr b/tests/ui/static/reference-to-mut-static.e2024.stderr index b18e214e84fea..9b3cbb4d19fc8 100644 --- a/tests/ui/static/reference-to-mut-static.e2024.stderr +++ b/tests/ui/static/reference-to-mut-static.e2024.stderr @@ -70,6 +70,22 @@ help: use `addr_of!` instead to create a raw pointer LL | foo(addr_of!(X)); | ~~~~~~~~~~~ -error: aborting due to 6 previous errors +error[E0796]: creating a shared reference to a mutable static + --> $DIR/reference-to-mut-static.rs:44:17 + | +LL | let _ = Z.len(); + | ^^^^^^^ shared reference to mutable static + | + = 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 + +error[E0796]: creating a shared reference to a mutable static + --> $DIR/reference-to-mut-static.rs:47:17 + | +LL | let _ = Z[0]; + | ^^^^ shared reference to mutable static + | + = 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 + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0796`. diff --git a/tests/ui/static/reference-to-mut-static.rs b/tests/ui/static/reference-to-mut-static.rs index af2cab7dd8723..3bf85858ff1af 100644 --- a/tests/ui/static/reference-to-mut-static.rs +++ b/tests/ui/static/reference-to-mut-static.rs @@ -42,7 +42,11 @@ fn main() { static mut Z: &[i32; 3] = &[0, 1, 2]; let _ = Z.len(); + //[e2024]~^ ERROR creating a shared reference to a mutable static [E0796] + //[e2021]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs] let _ = Z[0]; + //[e2024]~^ ERROR creating a shared reference to a mutable static [E0796] + //[e2021]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs] let _ = format!("{:?}", Z); } }