Skip to content

Commit dc0117a

Browse files
committed
Add dual tests for const_mut_refs
1 parent 19ddfb5 commit dc0117a

6 files changed

+39
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: dereferencing raw pointers in constants is unstable
2+
--> $DIR/projection_qualif.rs:11:18
3+
|
4+
LL | unsafe { *b = 5; }
5+
| ^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/51911
8+
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/consts/projection_qualif.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
// revisions: stock mut_refs
2+
3+
#![cfg_attr(mut_refs, feature(const_mut_refs))]
4+
15
use std::cell::Cell;
26

37
const FOO: &u32 = {
48
let mut a = 42;
59
{
6-
let b: *mut u32 = &mut a; //~ ERROR may only refer to immutable values
10+
let b: *mut u32 = &mut a; //[stock]~ ERROR may only refer to immutable values
711
unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants
8-
//~^ contains unimplemented expression
12+
//[stock]~^ contains unimplemented expression
913
}
1014
&{a}
1115
};

src/test/ui/consts/projection_qualif.stderr renamed to src/test/ui/consts/projection_qualif.stock.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: references in constants may only refer to immutable values
2-
--> $DIR/projection_qualif.rs:6:27
2+
--> $DIR/projection_qualif.rs:10:27
33
|
44
LL | let b: *mut u32 = &mut a;
55
| ^^^^^^ constants require immutable values
@@ -8,7 +8,7 @@ LL | let b: *mut u32 = &mut a;
88
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
99

1010
error[E0658]: dereferencing raw pointers in constants is unstable
11-
--> $DIR/projection_qualif.rs:7:18
11+
--> $DIR/projection_qualif.rs:11:18
1212
|
1313
LL | unsafe { *b = 5; }
1414
| ^^^^^^
@@ -17,7 +17,7 @@ LL | unsafe { *b = 5; }
1717
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
1818

1919
error[E0019]: constant contains unimplemented expression type
20-
--> $DIR/projection_qualif.rs:7:18
20+
--> $DIR/projection_qualif.rs:11:18
2121
|
2222
LL | unsafe { *b = 5; }
2323
| ^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0080]: could not evaluate static initializer
2+
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
3+
|
4+
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify a static's initial value from another static's initializer
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
// revisions: stock mut_refs
2+
3+
#![cfg_attr(mut_refs, feature(const_mut_refs))]
4+
15
static mut STDERR_BUFFER_SPACE: u8 = 0;
26

37
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
4-
//~^ ERROR references in statics may only refer to immutable values
5-
//~| ERROR static contains unimplemented expression type
8+
//[mut_refs]~^ ERROR could not evaluate static initializer
9+
//[stock]~^^ ERROR references in statics may only refer to immutable values
10+
//[stock]~| ERROR static contains unimplemented expression type
611

712
fn main() {}

src/test/ui/consts/static_mut_containing_mut_ref2.stderr renamed to src/test/ui/consts/static_mut_containing_mut_ref2.stock.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: references in statics may only refer to immutable values
2-
--> $DIR/static_mut_containing_mut_ref2.rs:3:46
2+
--> $DIR/static_mut_containing_mut_ref2.rs:7:46
33
|
44
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
@@ -8,7 +8,7 @@ LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 4
88
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
99

1010
error[E0019]: static contains unimplemented expression type
11-
--> $DIR/static_mut_containing_mut_ref2.rs:3:45
11+
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
1212
|
1313
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)