2023-12-22 06:10:47 -06:00
|
|
|
//@ revisions: e2021 e2024
|
|
|
|
|
|
|
|
//@ [e2021] edition:2021
|
|
|
|
//@ [e2024] compile-flags: --edition 2024 -Z unstable-options
|
|
|
|
|
2024-02-17 13:01:56 -06:00
|
|
|
#![deny(static_mut_refs)]
|
2023-12-22 06:10:47 -06:00
|
|
|
|
|
|
|
use std::ptr::{addr_of, addr_of_mut};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
static mut X: i32 = 1;
|
|
|
|
|
|
|
|
static mut Y: i32 = 1;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let _y = &X;
|
2024-02-17 13:01:56 -06:00
|
|
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
|
|
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
2023-12-22 06:10:47 -06:00
|
|
|
|
|
|
|
let _y = &mut X;
|
2024-02-17 13:01:56 -06:00
|
|
|
//[e2024]~^ ERROR creating a mutable reference to a mutable static [E0796]
|
|
|
|
//[e2021]~^^ ERROR mutable reference to mutable static is discouraged [static_mut_refs]
|
2023-12-22 06:10:47 -06:00
|
|
|
|
|
|
|
let _z = addr_of_mut!(X);
|
|
|
|
|
|
|
|
let _p = addr_of!(X);
|
|
|
|
|
|
|
|
let ref _a = X;
|
2024-02-17 13:01:56 -06:00
|
|
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
|
|
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
2023-12-22 06:10:47 -06:00
|
|
|
|
|
|
|
let (_b, _c) = (&X, &Y);
|
2024-02-17 13:01:56 -06:00
|
|
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
|
|
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
|
|
|
//[e2024]~^^^ ERROR creating a shared reference to a mutable static [E0796]
|
|
|
|
//[e2021]~^^^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
2023-12-22 06:10:47 -06:00
|
|
|
|
|
|
|
foo(&X);
|
2024-02-17 13:01:56 -06:00
|
|
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
|
|
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
2023-12-22 06:10:47 -06:00
|
|
|
|
|
|
|
static mut Z: &[i32; 3] = &[0, 1, 2];
|
|
|
|
|
|
|
|
let _ = Z.len();
|
|
|
|
let _ = Z[0];
|
|
|
|
let _ = format!("{:?}", Z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo<'a>(_x: &'a i32) {}
|