Change:
Compiling this code on : results in ICE. Casting to anything smaller than /(, , , , , etc) also results in ICE. Casting to anything same size or larger(, , , , etc) works fine. Positive discriminant values also work fine. Version of rustc: (on rust playground) Compiler flags listed as used:
indicates that this was injected in Rust 1.40
Thanks for the report! Please always include the ICE message. This time, it seems to be

Discussion:
if let Some(discr) = operand.layout.ty.discriminant_for_variant(bx.tcx(), index) { <del> let discr_val = bx.cx().const_uint_big(ll_t_out, discr.val); </del> <ins> let discr_layout = bx.cx().layout_of(discr.ty); let discr_t = bx.cx().immediate_backend_type(discr_layout); let discr_val = bx.cx().const_uint_big(discr_t, discr.val); let discr_val = bx.intcast(discr_val, ll_t_out, discr.ty.is_signed()); </ins> return ( bx, OperandRef {

use rustc::ty::{self, Ty, TypeAndMut, TypeFoldable}; use rustc_ast::ast::FloatTy; use rustc_span::symbol::sym; <ins> use rustc_target::abi::LayoutOf; </ins> use rustc::mir::interpret::{InterpResult, PointerArithmetic, Scalar}; use rustc::mir::CastKind;

layout::Variants::Single { index } => { if let Some(discr) = src.layout.ty.discriminant_for_variant(*self.tcx, index) { assert!(src.layout.is_zst()); <del> return Ok(Scalar::from_uint(discr.val, dest_layout.size).into()); </del> <ins> let discr_layout = self.layout_of(discr.ty)?; return Ok(self .cast_from_int_like(discr.val, discr_layout, dest_layout)? .into()); </ins> } } layout::Variants::Multiple { .. } => {}

// (b) cast from an integer-like (including bool, char, enums). // In both cases we want the bits. let bits = self.force_bits(src.to_scalar()?, src.layout.size)?; <del> Ok(self.cast_from_int(bits, src.layout, dest_layout)?.into()) </del> <ins> Ok(self.cast_from_int_like(bits, src.layout, dest_layout)?.into()) </ins> } <del> fn cast_from_int( </del> <ins> fn cast_from_int_like( </ins> &self, v: u128, // raw bits src_layout: TyLayout<'tcx>,

<ins> // run-pass // Test a ZST enum whose dicriminant is ~0i128. This caused an ICE when casting to a i32. #[derive(Copy, Clone)] enum Nums { NegOne = -1, } const NEG_ONE_I8: i8 = Nums::NegOne as i8; const NEG_ONE_I16: i16 = Nums::NegOne as i16; const NEG_ONE_I32: i32 = Nums::NegOne as i32; const NEG_ONE_I64: i64 = Nums::NegOne as i64; const NEG_ONE_I128: i128 = Nums::NegOne as i128; #[inline(never)] fn identity<T>(t: T) -> T { t } fn test_as_arg(n: Nums) { assert_eq!(-1i8, n as i8); assert_eq!(-1i16, n as i16); assert_eq!(-1i32, n as i32); assert_eq!(-1i64, n as i64); assert_eq!(-1i128, n as i128); } fn main() { let kind = Nums::NegOne; assert_eq!(-1i8, kind as i8); assert_eq!(-1i16, kind as i16); assert_eq!(-1i32, kind as i32); assert_eq!(-1i64, kind as i64); assert_eq!(-1i128, kind as i128); assert_eq!(-1i8, identity(kind) as i8); assert_eq!(-1i16, identity(kind) as i16); assert_eq!(-1i32, identity(kind) as i32); assert_eq!(-1i64, identity(kind) as i64); assert_eq!(-1i128, identity(kind) as i128); test_as_arg(Nums::NegOne); assert_eq!(-1i8, NEG_ONE_I8); assert_eq!(-1i16, NEG_ONE_I16); assert_eq!(-1i32, NEG_ONE_I32); assert_eq!(-1i64, NEG_ONE_I64); assert_eq!(-1i128, NEG_ONE_I128); } </ins>