Skip to content

Commit 4ff353c

Browse files
committed
test dynamic check for ptr-int-casts (unleashed)
1 parent 4759090 commit 4ff353c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/test/ui/consts/miri_unleashed/ptr_arith.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ static CMP: () = {
1111
//~| "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
1212
};
1313

14-
static INT_PTR_ARITH: () = unsafe {
14+
static PTR_INT_CAST: () = {
15+
let x = &0 as *const _ as usize;
16+
//~^ ERROR could not evaluate static initializer
17+
//~| unable to turn pointer into raw bytes
18+
let _v = x == x;
19+
};
20+
21+
static PTR_INT_TRANSMUTE: () = unsafe {
1522
let x: usize = std::mem::transmute(&0);
1623
let _v = x + 0;
1724
//~^ ERROR could not evaluate static initializer

src/test/ui/consts/miri_unleashed/ptr_arith.stderr

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ LL | let _v = x == x;
55
| ^^^^^^ "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
66

77
error[E0080]: could not evaluate static initializer
8-
--> $DIR/ptr_arith.rs:16:14
8+
--> $DIR/ptr_arith.rs:15:13
9+
|
10+
LL | let x = &0 as *const _ as usize;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
12+
13+
error[E0080]: could not evaluate static initializer
14+
--> $DIR/ptr_arith.rs:23:14
915
|
1016
LL | let _v = x + 0;
1117
| ^^^^^ unable to turn pointer into raw bytes
@@ -17,7 +23,12 @@ help: skipping check that does not even have a feature gate
1723
|
1824
LL | let _v = x == x;
1925
| ^^^^^^
26+
help: skipping check that does not even have a feature gate
27+
--> $DIR/ptr_arith.rs:15:13
28+
|
29+
LL | let x = &0 as *const _ as usize;
30+
| ^^^^^^^^^^^^^^^^^^^^^^^
2031

21-
error: aborting due to 2 previous errors; 1 warning emitted
32+
error: aborting due to 3 previous errors; 1 warning emitted
2233

2334
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)