Skip to content

Commit 5be7414

Browse files
committed
add test case
1 parent 8a17b36 commit 5be7414

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn main() {
2+
// Make sure match uses the usual pointer comparison code path -- i.e., it should complain
3+
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw
4+
// bytes.
5+
let _: [u8; 0] = [4; { //~ ERROR could not evaluate repeat length
6+
match &1 as *const i32 as usize { //~ ERROR raw pointers cannot be cast to integers
7+
0 => 42, //~ ERROR constant contains unimplemented expression type
8+
//~^ NOTE "pointer arithmetic or comparison" needs an rfc before being allowed
9+
n => n,
10+
}
11+
}];
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0018]: raw pointers cannot be cast to integers in constants
2+
--> $DIR/match-test-ptr-null.rs:6:15
3+
|
4+
LL | match &1 as *const i32 as usize { //~ ERROR raw pointers cannot be cast to integers
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0019]: constant contains unimplemented expression type
8+
--> $DIR/match-test-ptr-null.rs:7:13
9+
|
10+
LL | 0 => 42, //~ ERROR constant contains unimplemented expression type
11+
| ^
12+
13+
error[E0080]: could not evaluate repeat length
14+
--> $DIR/match-test-ptr-null.rs:5:26
15+
|
16+
LL | let _: [u8; 0] = [4; { //~ ERROR could not evaluate repeat length
17+
| __________________________^
18+
LL | | match &1 as *const i32 as usize { //~ ERROR raw pointers cannot be cast to integers
19+
LL | | 0 => 42, //~ ERROR constant contains unimplemented expression type
20+
| | - "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
21+
LL | | //~^ NOTE "pointer arithmetic or comparison" needs an rfc before being allowed
22+
LL | | n => n,
23+
LL | | }
24+
LL | | }];
25+
| |_____^
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors occurred: E0018, E0019, E0080.
30+
For more information about an error, try `rustc --explain E0018`.

0 commit comments

Comments
 (0)