Rollup merge of #140056 - yuk1ty:fix-static-mut-error-message, r=jieyouxu
Fix a wrong error message in 2024 edition Fixes https://github.com/rust-lang/rust/issues/139952
This commit is contained in:
commit
1a766a8772
22 changed files with 91 additions and 93 deletions
|
|
@ -757,7 +757,7 @@ lint_single_use_lifetime = lifetime parameter `{$ident}` only used once
|
|||
|
||||
lint_span_use_eq_ctxt = use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`
|
||||
|
||||
lint_static_mut_refs_lint = creating a {$shared_label}reference to mutable static is discouraged
|
||||
lint_static_mut_refs_lint = creating a {$shared_label}reference to mutable static
|
||||
.label = {$shared_label}reference to mutable static
|
||||
.suggestion = use `&raw const` instead to create a raw pointer
|
||||
.suggestion_mut = use `&raw mut` instead to create a raw pointer
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ declare_lint! {
|
|||
/// This lint is "warn" by default on editions up to 2021, in 2024 is "deny".
|
||||
pub STATIC_MUT_REFS,
|
||||
Warn,
|
||||
"shared references or mutable references of mutable static is discouraged",
|
||||
"creating a shared reference to mutable static",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>",
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ LL | if result.is_ok() {
|
|||
LL | result.as_mut().unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> tests/ui/checked_unwrap/simple_conditionals.rs:183:12
|
||||
|
|
||||
LL | if X.is_some() {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ impl Foo {
|
|||
fn main() {
|
||||
unsafe {
|
||||
let sfoo: *mut Foo = &mut SFOO;
|
||||
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN mutable reference to mutable static [static_mut_refs]
|
||||
let x = (*sfoo).x();
|
||||
(*sfoo).x[1] += 1;
|
||||
*x += 1;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
warning: creating a mutable reference to mutable static is discouraged
|
||||
warning: creating a mutable reference to mutable static
|
||||
--> $DIR/borrowck-unsafe-static-mutable-borrows.rs:19:30
|
||||
|
|
||||
LL | let sfoo: *mut Foo = &mut SFOO;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ static mut BB: AA = AA::new();
|
|||
|
||||
fn main() {
|
||||
let ptr = unsafe { &mut BB };
|
||||
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN mutable reference to mutable static [static_mut_refs]
|
||||
for a in ptr.data.iter() {
|
||||
println!("{}", a);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
warning: creating a mutable reference to mutable static is discouraged
|
||||
warning: creating a mutable reference to mutable static
|
||||
--> $DIR/const_let_assign2.rs:18:24
|
||||
|
|
||||
LL | let ptr = unsafe { &mut BB };
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ fn arena() -> &'static ArenaSet<Vec<u8>> {
|
|||
|
||||
static mut ONCE: Once = Once::new();
|
||||
ONCE.call_once(|| {
|
||||
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
DATA = transmute
|
||||
::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
|
||||
(Box::new(__static_ref_initialize()));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/issue-39367.rs:22:13
|
||||
|
|
||||
LL | / ONCE.call_once(|| {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:38:18
|
||||
|
|
||||
LL | let _y = &X;
|
||||
|
|
@ -12,7 +12,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let _y = &raw const X;
|
||||
| +++++++++
|
||||
|
||||
warning: creating a mutable reference to mutable static is discouraged
|
||||
warning: creating a mutable reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:42:18
|
||||
|
|
||||
LL | let _y = &mut X;
|
||||
|
|
@ -25,7 +25,7 @@ help: use `&raw mut` instead to create a raw pointer
|
|||
LL | let _y = &raw mut X;
|
||||
| +++
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:50:22
|
||||
|
|
||||
LL | let ref _a = X;
|
||||
|
|
@ -34,7 +34,7 @@ LL | let ref _a = X;
|
|||
= 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
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:54:25
|
||||
|
|
||||
LL | let (_b, _c) = (&X, &Y);
|
||||
|
|
@ -47,7 +47,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let (_b, _c) = (&raw const X, &Y);
|
||||
| +++++++++
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:54:29
|
||||
|
|
||||
LL | let (_b, _c) = (&X, &Y);
|
||||
|
|
@ -60,7 +60,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let (_b, _c) = (&X, &raw const Y);
|
||||
| +++++++++
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:60:13
|
||||
|
|
||||
LL | foo(&X);
|
||||
|
|
@ -73,7 +73,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | foo(&raw const X);
|
||||
| +++++++++
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:66:17
|
||||
|
|
||||
LL | let _ = Z.len();
|
||||
|
|
@ -82,7 +82,7 @@ LL | let _ = Z.len();
|
|||
= 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
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:72:33
|
||||
|
|
||||
LL | let _ = format!("{:?}", Z);
|
||||
|
|
@ -91,7 +91,7 @@ LL | let _ = format!("{:?}", Z);
|
|||
= 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
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:76:18
|
||||
|
|
||||
LL | let _v = &A.value;
|
||||
|
|
@ -104,7 +104,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let _v = &raw const A.value;
|
||||
| +++++++++
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:80:18
|
||||
|
|
||||
LL | let _s = &A.s.value;
|
||||
|
|
@ -117,7 +117,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let _s = &raw const A.s.value;
|
||||
| +++++++++
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:84:22
|
||||
|
|
||||
LL | let ref _v = A.value;
|
||||
|
|
@ -126,7 +126,7 @@ LL | let ref _v = A.value;
|
|||
= 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
|
||||
|
||||
warning: creating a mutable reference to mutable static is discouraged
|
||||
warning: creating a mutable reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:14:14
|
||||
|
|
||||
LL | &mut ($x.0)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:38:18
|
||||
|
|
||||
LL | let _y = &X;
|
||||
|
|
@ -12,7 +12,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let _y = &raw const X;
|
||||
| +++++++++
|
||||
|
||||
error: creating a mutable reference to mutable static is discouraged
|
||||
error: creating a mutable reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:42:18
|
||||
|
|
||||
LL | let _y = &mut X;
|
||||
|
|
@ -25,7 +25,7 @@ help: use `&raw mut` instead to create a raw pointer
|
|||
LL | let _y = &raw mut X;
|
||||
| +++
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:50:22
|
||||
|
|
||||
LL | let ref _a = X;
|
||||
|
|
@ -34,7 +34,7 @@ LL | let ref _a = X;
|
|||
= 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
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:54:25
|
||||
|
|
||||
LL | let (_b, _c) = (&X, &Y);
|
||||
|
|
@ -47,7 +47,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let (_b, _c) = (&raw const X, &Y);
|
||||
| +++++++++
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:54:29
|
||||
|
|
||||
LL | let (_b, _c) = (&X, &Y);
|
||||
|
|
@ -60,7 +60,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let (_b, _c) = (&X, &raw const Y);
|
||||
| +++++++++
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:60:13
|
||||
|
|
||||
LL | foo(&X);
|
||||
|
|
@ -73,7 +73,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | foo(&raw const X);
|
||||
| +++++++++
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:66:17
|
||||
|
|
||||
LL | let _ = Z.len();
|
||||
|
|
@ -82,7 +82,7 @@ LL | let _ = Z.len();
|
|||
= 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
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:72:33
|
||||
|
|
||||
LL | let _ = format!("{:?}", Z);
|
||||
|
|
@ -91,7 +91,7 @@ LL | let _ = format!("{:?}", Z);
|
|||
= 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
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:76:18
|
||||
|
|
||||
LL | let _v = &A.value;
|
||||
|
|
@ -104,7 +104,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let _v = &raw const A.value;
|
||||
| +++++++++
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:80:18
|
||||
|
|
||||
LL | let _s = &A.s.value;
|
||||
|
|
@ -117,7 +117,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let _s = &raw const A.s.value;
|
||||
| +++++++++
|
||||
|
||||
error: creating a shared reference to mutable static is discouraged
|
||||
error: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:84:22
|
||||
|
|
||||
LL | let ref _v = A.value;
|
||||
|
|
@ -126,7 +126,7 @@ LL | let ref _v = A.value;
|
|||
= 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
|
||||
|
||||
error: creating a mutable reference to mutable static is discouraged
|
||||
error: creating a mutable reference to mutable static
|
||||
--> $DIR/static-mut-refs.rs:14:14
|
||||
|
|
||||
LL | &mut ($x.0)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ static mut FOO: (u32, u32) = (1, 2);
|
|||
macro_rules! bar {
|
||||
($x:expr) => {
|
||||
&mut ($x.0)
|
||||
//[e2021]~^ WARN creating a mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN creating a mutable reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a mutable reference to mutable static [static_mut_refs]
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -36,54 +36,54 @@ fn main() {
|
|||
|
||||
unsafe {
|
||||
let _y = &X;
|
||||
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
|
||||
|
||||
let _y = &mut X;
|
||||
//[e2021]~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN mutable reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR mutable reference to mutable static [static_mut_refs]
|
||||
|
||||
let _z = &raw mut X;
|
||||
|
||||
let _p = &raw const X;
|
||||
|
||||
let ref _a = X;
|
||||
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
|
||||
|
||||
let (_b, _c) = (&X, &Y);
|
||||
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^^^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
|
||||
//[e2021]~^^^ WARN shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^^^ ERROR shared reference to mutable static [static_mut_refs]
|
||||
|
||||
foo(&X);
|
||||
//[e2021]~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR shared reference to mutable static [static_mut_refs]
|
||||
|
||||
static mut Z: &[i32; 3] = &[0, 1, 2];
|
||||
|
||||
let _ = Z.len();
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
|
||||
|
||||
let _ = Z[0];
|
||||
|
||||
let _ = format!("{:?}", Z);
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
|
||||
|
||||
let _v = &A.value;
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
|
||||
|
||||
let _s = &A.s.value;
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
|
||||
|
||||
let ref _v = A.value;
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//[e2021]~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
//[e2024]~^^ ERROR creating a shared reference to mutable static [static_mut_refs]
|
||||
|
||||
let _x = bar!(FOO);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ struct S1 {
|
|||
impl S1 {
|
||||
fn new(_x: u64) -> S1 {
|
||||
S1 { a: unsafe { &mut X1 } }
|
||||
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN mutable reference to mutable static [static_mut_refs]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
warning: creating a mutable reference to mutable static is discouraged
|
||||
warning: creating a mutable reference to mutable static
|
||||
--> $DIR/borrowck-thread-local-static-mut-borrow-outlives-fn.rs:17:26
|
||||
|
|
||||
LL | S1 { a: unsafe { &mut X1 } }
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
#![allow(dead_code)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
|
||||
static mut n_mut: usize = 0;
|
||||
|
||||
static n: &'static usize = unsafe { &n_mut };
|
||||
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN shared reference to mutable static [static_mut_refs]
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: creating a shared reference to mutable static is discouraged
|
||||
--> $DIR/issue-15261.rs:8:37
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/issue-15261.rs:7:37
|
||||
|
|
||||
LL | static n: &'static usize = unsafe { &n_mut };
|
||||
| ^^^^^^ shared reference to mutable static
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
//Missing paren in diagnostic msg: https://github.com/rust-lang/rust/issues/131977
|
||||
//@check-pass
|
||||
|
||||
|
||||
static mut TEST: usize = 0;
|
||||
|
||||
fn main() {
|
||||
let _ = unsafe { (&TEST) as *const usize };
|
||||
//~^WARN creating a shared reference to mutable static is discouraged
|
||||
//~^WARN creating a shared reference to mutable static
|
||||
|
||||
let _ = unsafe { ((&mut TEST)) as *const usize };
|
||||
//~^WARN creating a mutable reference to mutable static is discouraged
|
||||
let _ = unsafe { (&mut TEST) as *const usize };
|
||||
//~^WARN creating a mutable reference to mutable static
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: creating a shared reference to mutable static is discouraged
|
||||
--> $DIR/static-mut-shared-parens.rs:8:22
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-shared-parens.rs:7:22
|
||||
|
|
||||
LL | let _ = unsafe { (&TEST) as *const usize };
|
||||
| ^^^^^^^ shared reference to mutable static
|
||||
|
|
@ -12,18 +12,18 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | let _ = unsafe { (&raw const TEST) as *const usize };
|
||||
| +++++++++
|
||||
|
||||
warning: creating a mutable reference to mutable static is discouraged
|
||||
--> $DIR/static-mut-shared-parens.rs:11:22
|
||||
warning: creating a mutable reference to mutable static
|
||||
--> $DIR/static-mut-shared-parens.rs:10:22
|
||||
|
|
||||
LL | let _ = unsafe { ((&mut TEST)) as *const usize };
|
||||
| ^^^^^^^^^^^^^ mutable reference to mutable static
|
||||
LL | let _ = unsafe { (&mut TEST) as *const usize };
|
||||
| ^^^^^^^^^^^ mutable reference to mutable static
|
||||
|
|
||||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
|
||||
= note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives
|
||||
help: use `&raw mut` instead to create a raw pointer
|
||||
|
|
||||
LL | let _ = unsafe { ((&raw mut TEST)) as *const usize };
|
||||
| +++
|
||||
LL | let _ = unsafe { (&raw mut TEST) as *const usize };
|
||||
| +++
|
||||
|
||||
warning: 2 warnings emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -17,23 +17,23 @@ fn static_bound_set(a: &'static mut isize) {
|
|||
|
||||
unsafe fn run() {
|
||||
assert_eq!(static_mut_xc::a, 3);
|
||||
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
static_mut_xc::a = 4;
|
||||
assert_eq!(static_mut_xc::a, 4);
|
||||
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
static_mut_xc::a += 1;
|
||||
assert_eq!(static_mut_xc::a, 5);
|
||||
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
static_mut_xc::a *= 3;
|
||||
assert_eq!(static_mut_xc::a, 15);
|
||||
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
static_mut_xc::a = -3;
|
||||
assert_eq!(static_mut_xc::a, -3);
|
||||
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
static_bound(&static_mut_xc::a);
|
||||
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN shared reference to mutable static [static_mut_refs]
|
||||
static_bound_set(&mut static_mut_xc::a);
|
||||
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN mutable reference to mutable static [static_mut_refs]
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-xc.rs:19:16
|
||||
|
|
||||
LL | assert_eq!(static_mut_xc::a, 3);
|
||||
|
|
@ -8,7 +8,7 @@ LL | assert_eq!(static_mut_xc::a, 3);
|
|||
= 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: `#[warn(static_mut_refs)]` on by default
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-xc.rs:22:16
|
||||
|
|
||||
LL | assert_eq!(static_mut_xc::a, 4);
|
||||
|
|
@ -17,7 +17,7 @@ LL | assert_eq!(static_mut_xc::a, 4);
|
|||
= 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
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-xc.rs:25:16
|
||||
|
|
||||
LL | assert_eq!(static_mut_xc::a, 5);
|
||||
|
|
@ -26,7 +26,7 @@ LL | assert_eq!(static_mut_xc::a, 5);
|
|||
= 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
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-xc.rs:28:16
|
||||
|
|
||||
LL | assert_eq!(static_mut_xc::a, 15);
|
||||
|
|
@ -35,7 +35,7 @@ LL | assert_eq!(static_mut_xc::a, 15);
|
|||
= 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
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-xc.rs:31:16
|
||||
|
|
||||
LL | assert_eq!(static_mut_xc::a, -3);
|
||||
|
|
@ -44,7 +44,7 @@ LL | assert_eq!(static_mut_xc::a, -3);
|
|||
= 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
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-mut-xc.rs:33:18
|
||||
|
|
||||
LL | static_bound(&static_mut_xc::a);
|
||||
|
|
@ -57,7 +57,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | static_bound(&raw const static_mut_xc::a);
|
||||
| +++++++++
|
||||
|
||||
warning: creating a mutable reference to mutable static is discouraged
|
||||
warning: creating a mutable reference to mutable static
|
||||
--> $DIR/static-mut-xc.rs:35:22
|
||||
|
|
||||
LL | static_bound_set(&mut static_mut_xc::a);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//@ run-pass
|
||||
|
||||
static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
|
||||
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN shared reference to mutable static [static_mut_refs]
|
||||
|
||||
struct StaticDoubleLinked {
|
||||
prev: &'static StaticDoubleLinked,
|
||||
|
|
@ -17,7 +17,7 @@ static L3: StaticDoubleLinked = StaticDoubleLinked { prev: &L2, next: &L1, data:
|
|||
pub fn main() {
|
||||
unsafe {
|
||||
assert_eq!(S, *(S as *const *const u8));
|
||||
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
|
||||
}
|
||||
|
||||
let mut test_vec = Vec::new();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-recursive.rs:3:36
|
||||
|
|
||||
LL | static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
|
||||
|
|
@ -12,7 +12,7 @@ help: use `&raw const` instead to create a raw pointer
|
|||
LL | static mut S: *const u8 = unsafe { &raw const S as *const *const u8 as *const u8 };
|
||||
| +++++++++
|
||||
|
||||
warning: creating a shared reference to mutable static is discouraged
|
||||
warning: creating a shared reference to mutable static
|
||||
--> $DIR/static-recursive.rs:19:20
|
||||
|
|
||||
LL | assert_eq!(S, *(S as *const *const u8));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue