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 2
2
3
3
// Test file taken from issue 45129 (https://github.com/rust-lang/rust/issues/45129)
4
4
5
- struct Foo { x : [ usize ; 2 ] }
5
+ struct Foo {
6
+ x : [ usize ; 2 ] ,
7
+ }
6
8
7
9
static mut SFOO : Foo = Foo { x : [ 23 , 32 ] } ;
8
10
9
11
impl 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
+ }
11
15
}
12
16
13
17
fn main ( ) {
14
18
unsafe {
15
19
let sfoo: * mut Foo = & mut SFOO ;
20
+ //~^ WARN use of mutable static is discouraged [static_mut_ref]
16
21
let x = ( * sfoo) . x ( ) ;
17
22
( * sfoo) . x [ 1 ] += 1 ;
18
23
* 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