Rollup merge of #55071 - oli-obk:const_cast_🍨, r=RalfJung

Fix ICE and report a human readable error

fixes #55063

r? @RalfJung
This commit is contained in:
kennytm 2018-10-19 11:03:30 +08:00
commit 89ebc6ce4f
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
6 changed files with 79 additions and 3 deletions

View file

@ -0,0 +1,5 @@
const fn foo(a: i32) -> Vec<i32> {
vec![1, 2, 3] //~ ERROR heap allocations are not allowed in const fn
}
fn main() {}

View file

@ -0,0 +1,10 @@
error: heap allocations are not allowed in const fn
--> $DIR/bad_const_fn_body_ice.rs:2:5
|
LL | vec![1, 2, 3] //~ ERROR heap allocations are not allowed in const fn
| ^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error

View file

@ -0,0 +1,14 @@
fn main() {}
const fn unsize(x: &[u8; 3]) -> &[u8] { x }
//~^ ERROR unsizing casts are not allowed in const fn
const fn closure() -> fn() { || {} }
//~^ ERROR function pointers in const fn are unstable
const fn closure2() {
(|| {}) as fn();
//~^ ERROR function pointers in const fn are unstable
}
const fn reify(f: fn()) -> unsafe fn() { f }
//~^ ERROR function pointers in const fn are unstable
const fn reify2() { main as unsafe fn(); }
//~^ ERROR function pointers in const fn are unstable

View file

@ -0,0 +1,32 @@
error: unsizing casts are not allowed in const fn
--> $DIR/cast_errors.rs:3:41
|
LL | const fn unsize(x: &[u8; 3]) -> &[u8] { x }
| ^
error: function pointers in const fn are unstable
--> $DIR/cast_errors.rs:5:23
|
LL | const fn closure() -> fn() { || {} }
| ^^^^
error: function pointers in const fn are unstable
--> $DIR/cast_errors.rs:8:5
|
LL | (|| {}) as fn();
| ^^^^^^^^^^^^^^^
error: function pointers in const fn are unstable
--> $DIR/cast_errors.rs:11:28
|
LL | const fn reify(f: fn()) -> unsafe fn() { f }
| ^^^^^^^^^^^
error: function pointers in const fn are unstable
--> $DIR/cast_errors.rs:13:21
|
LL | const fn reify2() { main as unsafe fn(); }
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 5 previous errors