Skip to content

Commit 846be82

Browse files
Update test for mutably borrowed statics in a const
This checks `static mut` as well for E0017, and blesses tests now that we emit an error for a mut deref.
1 parent a70ac50 commit 846be82

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/test/ui/error-codes/E0017.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
static X: i32 = 1;
22
const C: i32 = 2;
3+
static mut M: i32 = 3;
34

45
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
56
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
7+
//~| ERROR E0019
68
//~| ERROR cannot borrow
79
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
10+
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0017
811
fn main() {}

src/test/ui/error-codes/E0017.stderr

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
error[E0017]: references in constants may only refer to immutable values
2-
--> $DIR/E0017.rs:4:30
2+
--> $DIR/E0017.rs:5:30
33
|
44
LL | const CR: &'static mut i32 = &mut C;
55
| ^^^^^^ constants require immutable values
66

7+
error[E0019]: static contains unimplemented expression type
8+
--> $DIR/E0017.rs:6:39
9+
|
10+
LL | static STATIC_REF: &'static mut i32 = &mut X;
11+
| ^^^^^^
12+
713
error[E0017]: references in statics may only refer to immutable values
8-
--> $DIR/E0017.rs:5:39
14+
--> $DIR/E0017.rs:6:39
915
|
1016
LL | static STATIC_REF: &'static mut i32 = &mut X;
1117
| ^^^^^^ statics require immutable values
1218

1319
error[E0596]: cannot borrow immutable static item `X` as mutable
14-
--> $DIR/E0017.rs:5:39
20+
--> $DIR/E0017.rs:6:39
1521
|
1622
LL | static STATIC_REF: &'static mut i32 = &mut X;
1723
| ^^^^^^ cannot borrow as mutable
1824

1925
error[E0017]: references in statics may only refer to immutable values
20-
--> $DIR/E0017.rs:7:38
26+
--> $DIR/E0017.rs:9:38
2127
|
2228
LL | static CONST_REF: &'static mut i32 = &mut C;
2329
| ^^^^^^ statics require immutable values
2430

25-
error: aborting due to 4 previous errors
31+
error[E0017]: references in statics may only refer to immutable values
32+
--> $DIR/E0017.rs:10:52
33+
|
34+
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
35+
| ^^^^^^ statics require immutable values
36+
37+
error: aborting due to 6 previous errors
2638

27-
Some errors have detailed explanations: E0017, E0596.
39+
Some errors have detailed explanations: E0017, E0019, E0596.
2840
For more information about an error, try `rustc --explain E0017`.

0 commit comments

Comments
 (0)