Add dual tests for const_mut_refs
This commit is contained in:
parent
19ddfb545b
commit
dc0117a42c
6 changed files with 39 additions and 9 deletions
12
src/test/ui/consts/projection_qualif.mut_refs.stderr
Normal file
12
src/test/ui/consts/projection_qualif.mut_refs.stderr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/projection_qualif.rs:11:18
|
||||
|
|
||||
LL | unsafe { *b = 5; }
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: for more information, see https://github.com/rust-lang/rust/issues/51911
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
// revisions: stock mut_refs
|
||||
|
||||
#![cfg_attr(mut_refs, feature(const_mut_refs))]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
const FOO: &u32 = {
|
||||
let mut a = 42;
|
||||
{
|
||||
let b: *mut u32 = &mut a; //~ ERROR may only refer to immutable values
|
||||
let b: *mut u32 = &mut a; //[stock]~ ERROR may only refer to immutable values
|
||||
unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants
|
||||
//~^ contains unimplemented expression
|
||||
//[stock]~^ contains unimplemented expression
|
||||
}
|
||||
&{a}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
--> $DIR/projection_qualif.rs:6:27
|
||||
--> $DIR/projection_qualif.rs:10:27
|
||||
|
|
||||
LL | let b: *mut u32 = &mut a;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
@ -8,7 +8,7 @@ LL | let b: *mut u32 = &mut a;
|
|||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/projection_qualif.rs:7:18
|
||||
--> $DIR/projection_qualif.rs:11:18
|
||||
|
|
||||
LL | unsafe { *b = 5; }
|
||||
| ^^^^^^
|
||||
|
|
@ -17,7 +17,7 @@ LL | unsafe { *b = 5; }
|
|||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
|
||||
error[E0019]: constant contains unimplemented expression type
|
||||
--> $DIR/projection_qualif.rs:7:18
|
||||
--> $DIR/projection_qualif.rs:11:18
|
||||
|
|
||||
LL | unsafe { *b = 5; }
|
||||
| ^^^^^^
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
|
||||
|
|
||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify a static's initial value from another static's initializer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
|
@ -1,7 +1,12 @@
|
|||
// revisions: stock mut_refs
|
||||
|
||||
#![cfg_attr(mut_refs, feature(const_mut_refs))]
|
||||
|
||||
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
||||
|
||||
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
//~^ ERROR references in statics may only refer to immutable values
|
||||
//~| ERROR static contains unimplemented expression type
|
||||
//[mut_refs]~^ ERROR could not evaluate static initializer
|
||||
//[stock]~^^ ERROR references in statics may only refer to immutable values
|
||||
//[stock]~| ERROR static contains unimplemented expression type
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0658]: references in statics may only refer to immutable values
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:3:46
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:7:46
|
||||
|
|
||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
||||
|
|
@ -8,7 +8,7 @@ LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 4
|
|||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0019]: static contains unimplemented expression type
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:3:45
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
|
||||
|
|
||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Loading…
Add table
Add a link
Reference in a new issue