Skip to content

Commit 2456f33

Browse files
committed
Try to trigger some error cases
1 parent 3405204 commit 2456f33

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn main() {}
2+
3+
const fn unsize(x: &[u8; 3]) -> &[u8] { x }
4+
//~^ ERROR unsizing casts are not allowed in const fn
5+
const fn closure() -> fn() { || {} }
6+
//~^ ERROR function pointers in const fn are unstable
7+
const fn closure2() {
8+
(|| {}) as fn();
9+
//~^ ERROR function pointers in const fn are unstable
10+
}
11+
const fn reify(f: fn()) -> unsafe fn() { f }
12+
//~^ ERROR function pointers in const fn are unstable
13+
const fn reify2() { main as unsafe fn(); }
14+
//~^ ERROR function pointers in const fn are unstable
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: unsizing casts are not allowed in const fn
2+
--> $DIR/cast_errors.rs:3:41
3+
|
4+
LL | const fn unsize(x: &[u8; 3]) -> &[u8] { x }
5+
| ^
6+
7+
error: function pointers in const fn are unstable
8+
--> $DIR/cast_errors.rs:5:23
9+
|
10+
LL | const fn closure() -> fn() { || {} }
11+
| ^^^^
12+
13+
error: function pointers in const fn are unstable
14+
--> $DIR/cast_errors.rs:8:5
15+
|
16+
LL | (|| {}) as fn();
17+
| ^^^^^^^^^^^^^^^
18+
19+
error: function pointers in const fn are unstable
20+
--> $DIR/cast_errors.rs:11:28
21+
|
22+
LL | const fn reify(f: fn()) -> unsafe fn() { f }
23+
| ^^^^^^^^^^^
24+
25+
error: function pointers in const fn are unstable
26+
--> $DIR/cast_errors.rs:13:21
27+
|
28+
LL | const fn reify2() { main as unsafe fn(); }
29+
| ^^^^^^^^^^^^^^^^^^^
30+
31+
error: aborting due to 5 previous errors
32+

0 commit comments

Comments
 (0)