File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
src/test/ui/consts/miri_unleashed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ // compile-flags: -Zunleash-the-miri-inside-of-you
2+ #![ feature( core_intrinsics) ]
3+ #![ allow( const_err) ]
4+
5+ // A test demonstrating that we prevent doing even trivial
6+ // pointer arithmetic or comparison during CTFE.
7+
8+ static CMP : ( ) = {
9+ let x = & 0 as * const _ ;
10+ let _v = x == x;
11+ //~^ ERROR could not evaluate static initializer
12+ //~| NOTE pointer arithmetic or comparison
13+ } ;
14+
15+ static INT_PTR_ARITH : ( ) = unsafe {
16+ let x: usize = std:: mem:: transmute ( & 0 ) ;
17+ let _v = x + 0 ;
18+ //~^ ERROR could not evaluate static initializer
19+ //~| NOTE pointer-to-integer cast
20+ } ;
21+
22+ static PTR_ARITH : ( ) = unsafe {
23+ let x = & 0 as * const _ ;
24+ let _v = core:: intrinsics:: offset ( x, 0 ) ;
25+ //~^ ERROR could not evaluate static initializer
26+ //~| NOTE calling intrinsic `offset`
27+ } ;
28+
29+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0080]: could not evaluate static initializer
2+ --> $DIR/ptr_arith.rs:10:14
3+ |
4+ LL | let _v = x == x;
5+ | ^^^^^^ "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
6+
7+ error[E0080]: could not evaluate static initializer
8+ --> $DIR/ptr_arith.rs:17:14
9+ |
10+ LL | let _v = x + 0;
11+ | ^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
12+
13+ error[E0080]: could not evaluate static initializer
14+ --> $DIR/ptr_arith.rs:24:14
15+ |
16+ LL | let _v = core::intrinsics::offset(x, 0);
17+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "calling intrinsic `offset`" needs an rfc before being allowed inside constants
18+
19+ warning: skipping const checks
20+ |
21+ help: skipping check for `const_compare_raw_pointers` feature
22+ --> $DIR/ptr_arith.rs:10:14
23+ |
24+ LL | let _v = x == x;
25+ | ^^^^^^
26+ help: skipping check that does not even have a feature gate
27+ --> $DIR/ptr_arith.rs:16:20
28+ |
29+ LL | let x: usize = std::mem::transmute(&0);
30+ | ^^^^^^^^^^^^^^^^^^^^^^^
31+ help: skipping check that does not even have a feature gate
32+ --> $DIR/ptr_arith.rs:24:14
33+ |
34+ LL | let _v = core::intrinsics::offset(x, 0);
35+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
37+ error: aborting due to 3 previous errors; 1 warning emitted
38+
39+ For more information about this error, try `rustc --explain E0080`.
You can’t perform that action at this time.
0 commit comments