Change:
<short summary of the bugReturning from a const fn causes internal compiler error, with the message 'bad input type for cast'. I tried this code: Minimal example Original example I expected to see this happen: program compiles and prints 'Hello 1' or I get a compiler error. Instead, this happened: ICE
that gives the exact backtrace above.
Relavent code: The types here are and .
The actual bug would be here then, right?
Not quite sure, but the real bug is that we allow the keyword in const fn XD I already have a fix since yesterday, but the german bahn didn't give me electricity so my notebook died while tests were running
no ICE fix from the ICE? :p

Discussion:
} impl<'tcx> CastTy<'tcx> { <ins> /// Returns `Some` for integral/pointer casts. /// casts like unsizing casts will return `None` </ins> pub fn from_ty(t: Ty<'tcx>) -> Option<CastTy<'tcx>> { match t.sty { ty::Bool => Some(CastTy::Int(IntTy::Bool)),

Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) => { check_place(tcx, mir, place, span, PlaceMode::Read) } <del> Rvalue::Cast(_, operand, cast_ty) => { </del> <ins> Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { </ins> use rustc::ty::cast::CastTy; let cast_in = CastTy::from_ty(operand.ty(mir, tcx)).expect("bad input type for cast"); let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");

_ => check_operand(tcx, mir, operand, span), } } <ins> Rvalue::Cast(CastKind::UnsafeFnPointer, _, _) | Rvalue::Cast(CastKind::ClosureFnPointer, _, _) | Rvalue::Cast(CastKind::ReifyFnPointer, _, _) => Err(( span, "function pointer casts are not allowed in const fn".into(), )), Rvalue::Cast(CastKind::Unsize, _, _) => Err(( span, "unsizing casts are not allowed in const fn".into(), )), </ins> // binops are fine on integers Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { check_operand(tcx, mir, lhs, span)?;

)) } } <del> // checked by regular const fn checks Rvalue::NullaryOp(..) => Ok(()), </del> <ins> Rvalue::NullaryOp(NullOp::SizeOf, _) => Ok(()), Rvalue::NullaryOp(NullOp::Box, _) => Err(( span, "heap allocations are not allowed in const fn".into(), )), </ins> Rvalue::UnaryOp(_, operand) => { let ty = operand.ty(mir, tcx); if ty.is_integral() || ty.is_bool() {

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

<ins> 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 </ins>

<ins> 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 </ins>

<ins> 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 </ins>