File tree Expand file tree Collapse file tree 4 files changed +59
-2
lines changed Expand file tree Collapse file tree 4 files changed +59
-2
lines changed Original file line number Diff line number Diff line change 22
33// Test file taken from issue 45129 (https://github.com/rust-lang/rust/issues/45129)
44
5- struct Foo { x : [ usize ; 2 ] }
5+ struct Foo {
6+ x : [ usize ; 2 ] ,
7+ }
68
79static mut SFOO : Foo = Foo { x : [ 23 , 32 ] } ;
810
911impl Foo {
10- fn x ( & mut self ) -> & mut usize { & mut self . x [ 0 ] }
12+ fn x ( & mut self ) -> & mut usize {
13+ & mut self . x [ 0 ]
14+ }
1115}
1216
1317fn main ( ) {
1418 unsafe {
1519 let sfoo: * mut Foo = & mut SFOO ;
20+ //~^ WARN use of mutable static is discouraged [static_mut_ref]
1621 let x = ( * sfoo) . x ( ) ;
1722 ( * sfoo) . x [ 1 ] += 1 ;
1823 * x += 1 ;
Original file line number Diff line number Diff line change 1+ warning: use of mutable static is discouraged
2+ --> $DIR/borrowck-unsafe-static-mutable-borrows.rs:19:30
3+ |
4+ LL | let sfoo: *mut Foo = &mut SFOO;
5+ | ^^^^^^^^^ use of mutable static
6+ |
7+ = note: use of mutable static is a hard error from 2024 edition
8+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
9+ = note: `#[warn(static_mut_ref)]` on by default
10+
11+ warning: 1 warning emitted
12+
Original file line number Diff line number Diff line change 1+ #![ deny( static_mut_ref) ]
2+
3+ fn main ( ) {
4+ static mut X : i32 = 1 ;
5+ unsafe {
6+ let _y = & X ;
7+ //~^ ERROR use of mutable static is discouraged [static_mut_ref]
8+ }
9+ }
10+
11+ unsafe fn _foo ( ) {
12+ static mut X : i32 = 1 ;
13+ let _y = & X ;
14+ //~^ ERROR use of mutable static is discouraged [static_mut_ref]
15+ }
Original file line number Diff line number Diff line change 1+ error: use of mutable static is discouraged
2+ --> $DIR/lint_static_mut_ref.rs:6:18
3+ |
4+ LL | let _y = &X;
5+ | ^^ use of mutable static
6+ |
7+ = note: use of mutable static is a hard error from 2024 edition
8+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
9+ note: the lint level is defined here
10+ --> $DIR/lint_static_mut_ref.rs:1:9
11+ |
12+ LL | #![deny(static_mut_ref)]
13+ | ^^^^^^^^^^^^^^
14+
15+ error: use of mutable static is discouraged
16+ --> $DIR/lint_static_mut_ref.rs:13:14
17+ |
18+ LL | let _y = &X;
19+ | ^^ use of mutable static
20+ |
21+ = note: use of mutable static is a hard error from 2024 edition
22+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
23+
24+ error: aborting due to 2 previous errors
25+
You can’t perform that action at this time.
0 commit comments