test dynamic check for ptr-int-casts (unleashed)

This commit is contained in:
Ralf Jung 2021-07-13 00:25:31 +02:00
parent 4759090d15
commit 4ff353cd6e
2 changed files with 21 additions and 3 deletions

View File

@ -11,7 +11,14 @@ static CMP: () = {
//~| "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
};
static INT_PTR_ARITH: () = unsafe {
static PTR_INT_CAST: () = {
let x = &0 as *const _ as usize;
//~^ ERROR could not evaluate static initializer
//~| unable to turn pointer into raw bytes
let _v = x == x;
};
static PTR_INT_TRANSMUTE: () = unsafe {
let x: usize = std::mem::transmute(&0);
let _v = x + 0;
//~^ ERROR could not evaluate static initializer

View File

@ -5,7 +5,13 @@ LL | let _v = x == x;
| ^^^^^^ "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
error[E0080]: could not evaluate static initializer
--> $DIR/ptr_arith.rs:16:14
--> $DIR/ptr_arith.rs:15:13
|
LL | let x = &0 as *const _ as usize;
| ^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
error[E0080]: could not evaluate static initializer
--> $DIR/ptr_arith.rs:23:14
|
LL | let _v = x + 0;
| ^^^^^ unable to turn pointer into raw bytes
@ -17,7 +23,12 @@ help: skipping check that does not even have a feature gate
|
LL | let _v = x == x;
| ^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/ptr_arith.rs:15:13
|
LL | let x = &0 as *const _ as usize;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 3 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.