File tree 2 files changed +35
-0
lines changed
src/test/ui/consts/const-eval
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Test for the behavior described in <https://github.com/rust-lang/rust/issues/87184>.
2
+ #![ feature( const_mut_refs, const_raw_ptr_deref) ]
3
+
4
+ const PARTIAL_OVERWRITE : ( ) = {
5
+ let mut p = & 42 ;
6
+ unsafe {
7
+ let ptr: * mut _ = & mut p;
8
+ * ( ptr as * mut u8 ) = 123 ; //~ ERROR any use of this value
9
+ //~| unable to overwrite parts of a pointer
10
+ //~| WARN previously accepted
11
+ }
12
+ let x = * p;
13
+ } ;
14
+
15
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: any use of this value will cause an error
2
+ --> $DIR/partial_ptr_overwrite.rs:8:9
3
+ |
4
+ LL | / const PARTIAL_OVERWRITE: () = {
5
+ LL | | let mut p = &42;
6
+ LL | | unsafe {
7
+ LL | | let ptr: *mut _ = &mut p;
8
+ LL | | *(ptr as *mut u8) = 123;
9
+ | | ^^^^^^^^^^^^^^^^^^^^^^^ unable to overwrite parts of a pointer in memory at alloc4
10
+ ... |
11
+ LL | | let x = *p;
12
+ LL | | };
13
+ | |__-
14
+ |
15
+ = note: `#[deny(const_err)]` on by default
16
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
17
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
18
+
19
+ error: aborting due to previous error
20
+
You can’t perform that action at this time.
0 commit comments