diff --git a/compiler/rustc_error_codes/src/error_codes/E0796.md b/compiler/rustc_error_codes/src/error_codes/E0796.md index cea18f8db851f..32570f79541d7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0796.md +++ b/compiler/rustc_error_codes/src/error_codes/E0796.md @@ -16,7 +16,11 @@ unsafe { fn foo<'a>(_x: &'a i32) {} ``` -Mutable statics can be written to by multiple threads: aliasing violations or -data races will cause undefined behavior. +a mutable reference supposedly lives forever, so creating more than one +is very dangerous and they can accidentally be used in overlapping ways. -Reference of mutable static is a hard error from 2024 edition. +a shared reference supposedly lives forever, so if there is ever also a +mutable reference created that is very dangerous as they can accidentally +be used in overlapping ways. + +Reference to mutable static is a hard error in 2024 edition. diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index a61cfd0e4ce9a..aa3106ee0559a 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -373,19 +373,21 @@ hir_analysis_start_not_target_feature = `#[start]` function is not allowed to ha hir_analysis_start_not_track_caller = `#[start]` function is not allowed to be `#[track_caller]` .label = `#[start]` function is not allowed to be `#[track_caller]` -hir_analysis_static_mut_ref = reference of mutable static is disallowed +hir_analysis_static_mut_ref = reference to mutable static is disallowed .label = reference of mutable static - .note = mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + .note = a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + .note_mut = a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways .suggestion = shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer .suggestion_mut = mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer -hir_analysis_static_mut_ref_lint = {$shared}reference of mutable static is discouraged +hir_analysis_static_mut_ref_lint = {$shared}reference to mutable static is discouraged .label = shared reference of mutable static .label_mut = mutable reference of mutable static .suggestion = shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer .suggestion_mut = mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer - .note = reference of mutable static is a hard error from 2024 edition - .why_note = mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + .note = reference of mutable static is a hard error in 2024 edition + .why_note = a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + .why_note_mut = a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways hir_analysis_static_specialize = cannot specialize on `'static` lifetime diff --git a/compiler/rustc_hir_analysis/src/check/errs.rs b/compiler/rustc_hir_analysis/src/check/errs.rs index 87a1f3d342580..cf1b454cd0d63 100644 --- a/compiler/rustc_hir_analysis/src/check/errs.rs +++ b/compiler/rustc_hir_analysis/src/check/errs.rs @@ -71,7 +71,7 @@ fn handle_static_mut_ref( } else { errors::StaticMutRefSugg::Shared { span, var } }; - tcx.sess.parse_sess.dcx.emit_err(errors::StaticMutRef { span, sugg }); + tcx.sess.parse_sess.dcx.emit_err(errors::StaticMutRef { span, note_mut: (), sugg }); return; } @@ -92,6 +92,6 @@ fn handle_static_mut_ref( STATIC_MUT_REF, hir_id, span, - errors::RefOfMutStatic { shared, why_note: (), label, sugg }, + errors::RefOfMutStatic { shared, why_note: (), why_note_mut: (), label, sugg }, ); } diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 6a505b961974f..e907e92bbc390 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -1459,6 +1459,8 @@ pub struct StaticMutRef { #[primary_span] #[label] pub span: Span, + #[note(hir_analysis_note_mut)] + pub note_mut: (), #[subdiagnostic] pub sugg: StaticMutRefSugg, } @@ -1497,6 +1499,8 @@ pub struct RefOfMutStatic<'a> { pub shared: &'a str, #[note(hir_analysis_why_note)] pub why_note: (), + #[note(hir_analysis_why_note_mut)] + pub why_note_mut: (), #[subdiagnostic] pub label: RefOfMutStaticLabel, #[subdiagnostic] diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 6a2a2c1e48e2a..45aae4eccea80 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1807,7 +1807,7 @@ declare_lint! { /// Shared or mutable references of mutable static are almost always a mistake and /// can lead to undefined behavior and various other problems in your code. /// - /// This lint is "warn" by default on editions up to 2021, from 2024 there is + /// This lint is "warn" by default on editions up to 2021,in 2024 there is /// a hard error instead. pub STATIC_MUT_REF, Warn, diff --git a/tests/ui/abi/statics/static-mut-foreign.rs b/tests/ui/abi/statics/static-mut-foreign.rs index eb732e7c2c31f..8b1b9c7abccb5 100644 --- a/tests/ui/abi/statics/static-mut-foreign.rs +++ b/tests/ui/abi/statics/static-mut-foreign.rs @@ -33,9 +33,9 @@ unsafe fn run() { rust_dbg_static_mut = -3; assert_eq!(rust_dbg_static_mut, -3); static_bound(&rust_dbg_static_mut); - //~^ WARN shared reference of mutable static is discouraged [static_mut_ref] + //~^ WARN shared reference to mutable static is discouraged [static_mut_ref] static_bound_set(&mut rust_dbg_static_mut); - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } pub fn main() { diff --git a/tests/ui/abi/statics/static-mut-foreign.stderr b/tests/ui/abi/statics/static-mut-foreign.stderr index 144ac056f87e4..47babebd50359 100644 --- a/tests/ui/abi/statics/static-mut-foreign.stderr +++ b/tests/ui/abi/statics/static-mut-foreign.stderr @@ -1,27 +1,29 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/static-mut-foreign.rs:35:18 | LL | static_bound(&rust_dbg_static_mut); | ^^^^^^^^^^^^^^^^^^^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | static_bound(addr_of!(rust_dbg_static_mut)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/static-mut-foreign.rs:37:22 | LL | static_bound_set(&mut rust_dbg_static_mut); | ^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | LL | static_bound_set(addr_of_mut!(rust_dbg_static_mut)); diff --git a/tests/ui/borrowck/borrowck-access-permissions.rs b/tests/ui/borrowck/borrowck-access-permissions.rs index 1638644103ba4..60efd91fdc318 100644 --- a/tests/ui/borrowck/borrowck-access-permissions.rs +++ b/tests/ui/borrowck/borrowck-access-permissions.rs @@ -16,7 +16,7 @@ fn main() { let _y1 = &mut static_x; //~ ERROR [E0596] unsafe { let _y2 = &mut static_x_mut; - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } } diff --git a/tests/ui/borrowck/borrowck-access-permissions.stderr b/tests/ui/borrowck/borrowck-access-permissions.stderr index 93d92295dd9b6..824c0c9ddb9e9 100644 --- a/tests/ui/borrowck/borrowck-access-permissions.stderr +++ b/tests/ui/borrowck/borrowck-access-permissions.stderr @@ -1,12 +1,13 @@ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/borrowck-access-permissions.rs:18:23 | LL | let _y2 = &mut static_x_mut; | ^^^^^^^^^^^^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | diff --git a/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.rs b/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.rs index 1bf079e24cae4..934f511c2f059 100644 --- a/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.rs +++ b/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.rs @@ -17,7 +17,7 @@ impl Foo { fn main() { unsafe { let sfoo: *mut Foo = &mut SFOO; - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] let x = (*sfoo).x(); (*sfoo).x[1] += 1; *x += 1; diff --git a/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.stderr b/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.stderr index 7a3824f79a4c2..be9fff2b93337 100644 --- a/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.stderr +++ b/tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.stderr @@ -1,12 +1,13 @@ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/borrowck-unsafe-static-mutable-borrows.rs:19:30 | LL | let sfoo: *mut Foo = &mut SFOO; | ^^^^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | diff --git a/tests/ui/borrowck/issue-20801.rs b/tests/ui/borrowck/issue-20801.rs index ec83af5d5dfc6..cc8cba9ff480d 100644 --- a/tests/ui/borrowck/issue-20801.rs +++ b/tests/ui/borrowck/issue-20801.rs @@ -12,7 +12,7 @@ fn imm_ref() -> &'static T { fn mut_ref() -> &'static mut T { unsafe { &mut GLOBAL_MUT_T } - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } fn mut_ptr() -> *mut T { diff --git a/tests/ui/borrowck/issue-20801.stderr b/tests/ui/borrowck/issue-20801.stderr index b2bee2d880394..44aee26a91028 100644 --- a/tests/ui/borrowck/issue-20801.stderr +++ b/tests/ui/borrowck/issue-20801.stderr @@ -1,12 +1,13 @@ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/issue-20801.rs:14:14 | LL | unsafe { &mut GLOBAL_MUT_T } | ^^^^^^^^^^^^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | diff --git a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs index 9b172b4131911..d1cc0de47598a 100644 --- a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs +++ b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs @@ -10,7 +10,7 @@ mod borrowck_closures_unique { //~^ ERROR is not declared as mutable unsafe { c1(&mut Y); - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } } } @@ -25,7 +25,7 @@ mod borrowck_closures_unique_grandparent { }; unsafe { c1(&mut Z); - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } } } @@ -62,7 +62,7 @@ fn main() { static mut X: isize = 2; unsafe { borrowck_closures_unique::e(&mut X); - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } mutability_errors::capture_assign_whole((1000,)); diff --git a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr index e4e4947fce1c1..815263ad1fa52 100644 --- a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr +++ b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr @@ -1,41 +1,44 @@ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:12:16 | LL | c1(&mut Y); | ^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | LL | c1(addr_of_mut!(Y)); | ~~~~~~~~~~~~~~~ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:27:16 | LL | c1(&mut Z); | ^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | LL | c1(addr_of_mut!(Z)); | ~~~~~~~~~~~~~~~ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37 | LL | borrowck_closures_unique::e(&mut X); | ^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | LL | borrowck_closures_unique::e(addr_of_mut!(X)); diff --git a/tests/ui/consts/const_let_assign2.rs b/tests/ui/consts/const_let_assign2.rs index 1c7afe0e3d6cb..5f7204251ceb1 100644 --- a/tests/ui/consts/const_let_assign2.rs +++ b/tests/ui/consts/const_let_assign2.rs @@ -16,7 +16,7 @@ static mut BB: AA = AA::new(); fn main() { let ptr = unsafe { &mut BB }; - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] for a in ptr.data.iter() { println!("{}", a); } diff --git a/tests/ui/consts/const_let_assign2.stderr b/tests/ui/consts/const_let_assign2.stderr index 2764153a8a590..ce4f91a2a6799 100644 --- a/tests/ui/consts/const_let_assign2.stderr +++ b/tests/ui/consts/const_let_assign2.stderr @@ -1,12 +1,13 @@ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/const_let_assign2.rs:18:24 | LL | let ptr = unsafe { &mut BB }; | ^^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | diff --git a/tests/ui/consts/const_refs_to_static_fail_invalid.rs b/tests/ui/consts/const_refs_to_static_fail_invalid.rs index 665b876c43e2c..ba808b20a6b2a 100644 --- a/tests/ui/consts/const_refs_to_static_fail_invalid.rs +++ b/tests/ui/consts/const_refs_to_static_fail_invalid.rs @@ -43,8 +43,8 @@ fn mutable() { // This *must not build*, the constant we are matching against // could change its value! match &42 { - C => {}, //~ERROR: could not evaluate constant pattern - _ => {}, + C => {} //~ERROR: could not evaluate constant pattern + _ => {} } } diff --git a/tests/ui/consts/const_refs_to_static_fail_invalid.stderr b/tests/ui/consts/const_refs_to_static_fail_invalid.stderr index 082f8532444ad..4ff15f0c28b8f 100644 --- a/tests/ui/consts/const_refs_to_static_fail_invalid.stderr +++ b/tests/ui/consts/const_refs_to_static_fail_invalid.stderr @@ -46,7 +46,7 @@ LL | const C: &i32 = unsafe { &S_MUT }; error: could not evaluate constant pattern --> $DIR/const_refs_to_static_fail_invalid.rs:46:9 | -LL | C => {}, +LL | C => {} | ^ error: aborting due to 6 previous errors 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 52603744c45fc..0de442eea8340 100644 --- a/tests/ui/drop/issue-23338-ensure-param-drop-order.rs +++ b/tests/ui/drop/issue-23338-ensure-param-drop-order.rs @@ -91,7 +91,7 @@ pub mod d { pub fn max_width() -> u32 { unsafe { (mem::size_of_val(&trails) * 8) as u32 - //~^ WARN shared reference of mutable static is discouraged [static_mut_ref] + //~^ WARN shared reference to mutable static is discouraged [static_mut_ref] } } 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 fd36ccbcbee47..8e76ffd28bc52 100644 --- a/tests/ui/drop/issue-23338-ensure-param-drop-order.stderr +++ b/tests/ui/drop/issue-23338-ensure-param-drop-order.stderr @@ -1,12 +1,13 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/issue-23338-ensure-param-drop-order.rs:93:31 | LL | (mem::size_of_val(&trails) * 8) as u32 | ^^^^^^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | diff --git a/tests/ui/error-codes/E0017.rs b/tests/ui/error-codes/E0017.rs index 9d3433fa543fd..2622162e5fa93 100644 --- a/tests/ui/error-codes/E0017.rs +++ b/tests/ui/error-codes/E0017.rs @@ -13,6 +13,6 @@ static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable references are no //~| WARN taking a mutable static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR mutable references are not -//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] +//~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] fn main() {} diff --git a/tests/ui/error-codes/E0017.stderr b/tests/ui/error-codes/E0017.stderr index 2a70f2ee0ae82..e054b3cf0aac5 100644 --- a/tests/ui/error-codes/E0017.stderr +++ b/tests/ui/error-codes/E0017.stderr @@ -1,12 +1,13 @@ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/E0017.rs:15:52 | LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; | ^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | diff --git a/tests/ui/issues/issue-23611-enum-swap-in-drop.rs b/tests/ui/issues/issue-23611-enum-swap-in-drop.rs index b967e6aecdd43..e1f6007f6ebe5 100644 --- a/tests/ui/issues/issue-23611-enum-swap-in-drop.rs +++ b/tests/ui/issues/issue-23611-enum-swap-in-drop.rs @@ -187,7 +187,7 @@ pub mod d { pub fn max_width() -> u32 { unsafe { (mem::size_of_val(&trails) * 8) as u32 - //~^ WARN shared reference of mutable static is discouraged [static_mut_ref] + //~^ WARN shared reference to mutable static is discouraged [static_mut_ref] } } diff --git a/tests/ui/issues/issue-23611-enum-swap-in-drop.stderr b/tests/ui/issues/issue-23611-enum-swap-in-drop.stderr index 14a986a333264..088030476cc75 100644 --- a/tests/ui/issues/issue-23611-enum-swap-in-drop.stderr +++ b/tests/ui/issues/issue-23611-enum-swap-in-drop.stderr @@ -1,12 +1,13 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/issue-23611-enum-swap-in-drop.rs:189:31 | LL | (mem::size_of_val(&trails) * 8) as u32 | ^^^^^^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | diff --git a/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.rs b/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.rs index 8eb544e8ab9d2..4c902f11e3542 100644 --- a/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.rs +++ b/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.rs @@ -15,7 +15,7 @@ struct S1 { impl S1 { fn new(_x: u64) -> S1 { S1 { a: unsafe { &mut X1 } } - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } } diff --git a/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.stderr b/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.stderr index 17217cd5859d0..ef8a6a2253e0f 100644 --- a/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.stderr +++ b/tests/ui/nll/borrowck-thread-local-static-mut-borrow-outlives-fn.stderr @@ -1,12 +1,13 @@ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/borrowck-thread-local-static-mut-borrow-outlives-fn.rs:17:26 | LL | S1 { a: unsafe { &mut X1 } } | ^^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | diff --git a/tests/ui/static/reference-of-mut-static-safe.e2021.stderr b/tests/ui/static/reference-of-mut-static-safe.e2021.stderr index 16f47ace3a930..48d36f69b681a 100644 --- a/tests/ui/static/reference-of-mut-static-safe.e2021.stderr +++ b/tests/ui/static/reference-of-mut-static-safe.e2021.stderr @@ -1,12 +1,13 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/reference-of-mut-static-safe.rs:9:14 | LL | let _x = &X; | ^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | diff --git a/tests/ui/static/reference-of-mut-static-safe.e2024.stderr b/tests/ui/static/reference-of-mut-static-safe.e2024.stderr index 53f81179de55a..6a58819b4bd1e 100644 --- a/tests/ui/static/reference-of-mut-static-safe.e2024.stderr +++ b/tests/ui/static/reference-of-mut-static-safe.e2024.stderr @@ -1,10 +1,11 @@ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static-safe.rs:9:14 | LL | let _x = &X; | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let _x = addr_of!(X); diff --git a/tests/ui/static/reference-of-mut-static-safe.rs b/tests/ui/static/reference-of-mut-static-safe.rs index 5cb1a03bef512..9fb804c33ddc4 100644 --- a/tests/ui/static/reference-of-mut-static-safe.rs +++ b/tests/ui/static/reference-of-mut-static-safe.rs @@ -7,7 +7,7 @@ fn main() { static mut X: i32 = 1; let _x = &X; - //[e2024]~^ reference of mutable static is disallowed [E0796] + //[e2024]~^ reference to mutable static is disallowed [E0796] //[e2021]~^^ use of mutable static is unsafe and requires unsafe function or block [E0133] - //[e2021]~^^^ shared reference of mutable static is discouraged [static_mut_ref] + //[e2021]~^^^ shared reference to mutable static is discouraged [static_mut_ref] } diff --git a/tests/ui/static/reference-of-mut-static-unsafe-fn.rs b/tests/ui/static/reference-of-mut-static-unsafe-fn.rs index 6b1e77850e50d..3d90bb6fbe28e 100644 --- a/tests/ui/static/reference-of-mut-static-unsafe-fn.rs +++ b/tests/ui/static/reference-of-mut-static-unsafe-fn.rs @@ -7,17 +7,17 @@ unsafe fn _foo() { static mut Y: i32 = 1; let _y = &X; - //~^ ERROR reference of mutable static is disallowed + //~^ ERROR reference to mutable static is disallowed let ref _a = X; - //~^ ERROR reference of mutable static is disallowed + //~^ ERROR reference to mutable static is disallowed let (_b, _c) = (&X, &Y); - //~^ ERROR reference of mutable static is disallowed - //~^^ ERROR reference of mutable static is disallowed + //~^ ERROR reference to mutable static is disallowed + //~^^ ERROR reference to mutable static is disallowed foo(&X); - //~^ ERROR reference of mutable static is disallowed + //~^ ERROR reference to mutable static is disallowed } fn foo<'a>(_x: &'a i32) {} diff --git a/tests/ui/static/reference-of-mut-static-unsafe-fn.stderr b/tests/ui/static/reference-of-mut-static-unsafe-fn.stderr index 5c6fdedfa96f7..65fecc46b23c2 100644 --- a/tests/ui/static/reference-of-mut-static-unsafe-fn.stderr +++ b/tests/ui/static/reference-of-mut-static-unsafe-fn.stderr @@ -1,58 +1,63 @@ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static-unsafe-fn.rs:9:14 | LL | let _y = &X; | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let _y = addr_of!(X); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static-unsafe-fn.rs:12:18 | LL | let ref _a = X; | ^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let ref _a = addr_of!(X); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static-unsafe-fn.rs:15:21 | LL | let (_b, _c) = (&X, &Y); | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let (_b, _c) = (addr_of!(X), &Y); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static-unsafe-fn.rs:15:25 | LL | let (_b, _c) = (&X, &Y); | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let (_b, _c) = (&X, addr_of!(Y)); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static-unsafe-fn.rs:19:9 | LL | foo(&X); | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | foo(addr_of!(X)); diff --git a/tests/ui/static/reference-of-mut-static.e2021.stderr b/tests/ui/static/reference-of-mut-static.e2021.stderr index 77a6b3d304bdb..d3375676613bb 100644 --- a/tests/ui/static/reference-of-mut-static.e2021.stderr +++ b/tests/ui/static/reference-of-mut-static.e2021.stderr @@ -1,12 +1,13 @@ -error: shared reference of mutable static is discouraged +error: shared reference to mutable static is discouraged --> $DIR/reference-of-mut-static.rs:16:18 | LL | let _y = &X; | ^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways note: the lint level is defined here --> $DIR/reference-of-mut-static.rs:6:9 | @@ -17,71 +18,76 @@ help: shared references are dangerous since if there's any kind of mutation of t LL | let _y = addr_of!(X); | ~~~~~~~~~~~ -error: mutable reference of mutable static is discouraged +error: mutable reference to mutable static is discouraged --> $DIR/reference-of-mut-static.rs:20:18 | LL | let _y = &mut X; | ^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | LL | let _y = addr_of_mut!(X); | ~~~~~~~~~~~~~~~ -error: shared reference of mutable static is discouraged +error: shared reference to mutable static is discouraged --> $DIR/reference-of-mut-static.rs:28:22 | LL | let ref _a = X; | ^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let ref _a = addr_of!(X); | ~~~~~~~~~~~ -error: shared reference of mutable static is discouraged +error: shared reference to mutable static is discouraged --> $DIR/reference-of-mut-static.rs:32:25 | LL | let (_b, _c) = (&X, &Y); | ^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let (_b, _c) = (addr_of!(X), &Y); | ~~~~~~~~~~~ -error: shared reference of mutable static is discouraged +error: shared reference to mutable static is discouraged --> $DIR/reference-of-mut-static.rs:32:29 | LL | let (_b, _c) = (&X, &Y); | ^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let (_b, _c) = (&X, addr_of!(Y)); | ~~~~~~~~~~~ -error: shared reference of mutable static is discouraged +error: shared reference to mutable static is discouraged --> $DIR/reference-of-mut-static.rs:38:13 | LL | foo(&X); | ^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | foo(addr_of!(X)); diff --git a/tests/ui/static/reference-of-mut-static.e2024.stderr b/tests/ui/static/reference-of-mut-static.e2024.stderr index f445ec65a5d24..f25b34aefab57 100644 --- a/tests/ui/static/reference-of-mut-static.e2024.stderr +++ b/tests/ui/static/reference-of-mut-static.e2024.stderr @@ -1,70 +1,76 @@ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static.rs:16:18 | LL | let _y = &X; | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let _y = addr_of!(X); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static.rs:20:18 | LL | let _y = &mut X; | ^^^^^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | LL | let _y = addr_of_mut!(X); | ~~~~~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static.rs:28:22 | LL | let ref _a = X; | ^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let ref _a = addr_of!(X); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static.rs:32:25 | LL | let (_b, _c) = (&X, &Y); | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let (_b, _c) = (addr_of!(X), &Y); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static.rs:32:29 | LL | let (_b, _c) = (&X, &Y); | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let (_b, _c) = (&X, addr_of!(Y)); | ~~~~~~~~~~~ -error[E0796]: reference of mutable static is disallowed +error[E0796]: reference to mutable static is disallowed --> $DIR/reference-of-mut-static.rs:38:13 | LL | foo(&X); | ^^ reference of mutable static | - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | foo(addr_of!(X)); diff --git a/tests/ui/static/reference-of-mut-static.rs b/tests/ui/static/reference-of-mut-static.rs index 01a3b1fbd9b51..4cd6d03e3deaf 100644 --- a/tests/ui/static/reference-of-mut-static.rs +++ b/tests/ui/static/reference-of-mut-static.rs @@ -14,30 +14,30 @@ fn main() { unsafe { let _y = &X; - //[e2024]~^ ERROR reference of mutable static is disallowed - //[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref] + //[e2024]~^ ERROR reference to mutable static is disallowed + //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_ref] let _y = &mut X; - //[e2024]~^ ERROR reference of mutable static is disallowed - //[e2021]~^^ ERROR mutable reference of mutable static is discouraged [static_mut_ref] + //[e2024]~^ ERROR reference to mutable static is disallowed + //[e2021]~^^ ERROR mutable reference to mutable static is discouraged [static_mut_ref] let _z = addr_of_mut!(X); let _p = addr_of!(X); let ref _a = X; - //[e2024]~^ ERROR reference of mutable static is disallowed - //[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref] + //[e2024]~^ ERROR reference to mutable static is disallowed + //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_ref] let (_b, _c) = (&X, &Y); - //[e2024]~^ ERROR reference of mutable static is disallowed - //[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref] - //[e2024]~^^^ ERROR reference of mutable static is disallowed - //[e2021]~^^^^ ERROR shared reference of mutable static is discouraged [static_mut_ref] + //[e2024]~^ ERROR reference to mutable static is disallowed + //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_ref] + //[e2024]~^^^ ERROR reference to mutable static is disallowed + //[e2021]~^^^^ ERROR shared reference to mutable static is discouraged [static_mut_ref] foo(&X); - //[e2024]~^ ERROR reference of mutable static is disallowed - //[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref] + //[e2024]~^ ERROR reference to mutable static is disallowed + //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_ref] static mut Z: &[i32; 3] = &[0, 1, 2]; diff --git a/tests/ui/static/safe-extern-statics-mut.rs b/tests/ui/static/safe-extern-statics-mut.rs index 1c0662e0a6cec..3abbdc5c554b9 100644 --- a/tests/ui/static/safe-extern-statics-mut.rs +++ b/tests/ui/static/safe-extern-statics-mut.rs @@ -10,8 +10,8 @@ extern "C" { fn main() { let b = B; //~ ERROR use of mutable static is unsafe let rb = &B; //~ ERROR use of mutable static is unsafe - //~^ WARN shared reference of mutable static is discouraged [static_mut_ref] + //~^ WARN shared reference to mutable static is discouraged [static_mut_ref] let xb = XB; //~ ERROR use of mutable static is unsafe let xrb = &XB; //~ ERROR use of mutable static is unsafe - //~^ WARN shared reference of mutable static is discouraged [static_mut_ref] + //~^ WARN shared reference to mutable static is discouraged [static_mut_ref] } diff --git a/tests/ui/static/safe-extern-statics-mut.stderr b/tests/ui/static/safe-extern-statics-mut.stderr index eda353ce6736f..71a724fbf0172 100644 --- a/tests/ui/static/safe-extern-statics-mut.stderr +++ b/tests/ui/static/safe-extern-statics-mut.stderr @@ -1,27 +1,29 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/safe-extern-statics-mut.rs:12:14 | LL | let rb = &B; | ^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let rb = addr_of!(B); | ~~~~~~~~~~~ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/safe-extern-statics-mut.rs:15:15 | LL | let xrb = &XB; | ^^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | let xrb = addr_of!(XB); diff --git a/tests/ui/statics/issue-15261.rs b/tests/ui/statics/issue-15261.rs index 14422329b7dc8..08fc6a02fca0d 100644 --- a/tests/ui/statics/issue-15261.rs +++ b/tests/ui/statics/issue-15261.rs @@ -7,6 +7,6 @@ static mut n_mut: usize = 0; static n: &'static usize = unsafe { &n_mut }; -//~^ WARN shared reference of mutable static is discouraged [static_mut_ref] +//~^ WARN shared reference to mutable static is discouraged [static_mut_ref] fn main() {} diff --git a/tests/ui/statics/issue-15261.stderr b/tests/ui/statics/issue-15261.stderr index 72d88ce1b3832..c5828372757c8 100644 --- a/tests/ui/statics/issue-15261.stderr +++ b/tests/ui/statics/issue-15261.stderr @@ -1,12 +1,13 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/issue-15261.rs:9:37 | LL | static n: &'static usize = unsafe { &n_mut }; | ^^^^^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | diff --git a/tests/ui/statics/static-mut-xc.rs b/tests/ui/statics/static-mut-xc.rs index 2fc265e02eaa3..327ed4f7b0251 100644 --- a/tests/ui/statics/static-mut-xc.rs +++ b/tests/ui/statics/static-mut-xc.rs @@ -26,9 +26,9 @@ unsafe fn run() { static_mut_xc::a = -3; assert_eq!(static_mut_xc::a, -3); static_bound(&static_mut_xc::a); - //~^ WARN shared reference of mutable static is discouraged [static_mut_ref] + //~^ WARN shared reference to mutable static is discouraged [static_mut_ref] static_bound_set(&mut static_mut_xc::a); - //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] + //~^ WARN mutable reference to mutable static is discouraged [static_mut_ref] } pub fn main() { diff --git a/tests/ui/statics/static-mut-xc.stderr b/tests/ui/statics/static-mut-xc.stderr index 37aa336bc50f7..b3a681d5c1606 100644 --- a/tests/ui/statics/static-mut-xc.stderr +++ b/tests/ui/statics/static-mut-xc.stderr @@ -1,27 +1,29 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/static-mut-xc.rs:28:18 | LL | static_bound(&static_mut_xc::a); | ^^^^^^^^^^^^^^^^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer | LL | static_bound(addr_of!(static_mut_xc::a)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ -warning: mutable reference of mutable static is discouraged +warning: mutable reference to mutable static is discouraged --> $DIR/static-mut-xc.rs:30:22 | LL | static_bound_set(&mut static_mut_xc::a); | ^^^^^^^^^^^^^^^^^^^^^ mutable reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer | LL | static_bound_set(addr_of_mut!(static_mut_xc::a)); diff --git a/tests/ui/statics/static-recursive.rs b/tests/ui/statics/static-recursive.rs index 216beb0206d9c..ffc7fac780971 100644 --- a/tests/ui/statics/static-recursive.rs +++ b/tests/ui/statics/static-recursive.rs @@ -1,7 +1,7 @@ // run-pass static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 }; -//~^ WARN shared reference of mutable static is discouraged [static_mut_ref] +//~^ WARN shared reference to mutable static is discouraged [static_mut_ref] struct StaticDoubleLinked { prev: &'static StaticDoubleLinked, diff --git a/tests/ui/statics/static-recursive.stderr b/tests/ui/statics/static-recursive.stderr index 15888e5c68d84..f93c22573499c 100644 --- a/tests/ui/statics/static-recursive.stderr +++ b/tests/ui/statics/static-recursive.stderr @@ -1,12 +1,13 @@ -warning: shared reference of mutable static is discouraged +warning: shared reference to mutable static is discouraged --> $DIR/static-recursive.rs:3:36 | LL | static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 }; | ^^ shared reference of mutable static | = note: for more information, see issue #114447 - = note: reference of mutable static is a hard error from 2024 edition - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior + = note: reference of mutable static is a hard error in 2024 edition + = note: a shared reference supposedly lives forever, so if there is ever also a mutable reference created that is very dangerous as they can accidentally be used in overlapping ways + = note: a mutable reference supposedly lives forever, so creating more than one is very dangerous and they can accidentally be used in overlapping ways = note: `#[warn(static_mut_ref)]` on by default help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer |