diff --git a/src/error.rs b/src/error.rs index a44b8cc76ebc..86f22d33a257 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ use std::error::Error; use std::fmt; use rustc::mir; -use rustc::ty::BareFnTy; +use rustc::ty::{BareFnTy, Ty}; use memory::Pointer; use rustc_const_math::ConstMathErr; use syntax::codemap::Span; @@ -46,6 +46,7 @@ pub enum EvalError<'tcx> { ModifiedConstantMemory, AssumptionNotHeld, InlineAsm, + TypeNotPrimitive(Ty<'tcx>), } pub type EvalResult<'tcx, T> = Result>; @@ -106,6 +107,8 @@ impl<'tcx> Error for EvalError<'tcx> { "`assume` argument was false", EvalError::InlineAsm => "cannot evaluate inline assembly", + EvalError::TypeNotPrimitive(_) => + "expected primitive type, got nonprimitive", } } @@ -134,6 +137,8 @@ impl<'tcx> fmt::Display for EvalError<'tcx> { EvalError::AlignmentCheckFailed { required, has } => write!(f, "tried to access memory with alignment {}, but alignment {} is required", has, required), + EvalError::TypeNotPrimitive(ref ty) => + write!(f, "expected primitive type, got {}", ty), _ => write!(f, "{}", self.description()), } } diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index b72feba8bc05..6454c7641274 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -1325,11 +1325,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { PrimValKind::from_uint_size(size) } } else { - bug!("primitive read of non-clike enum: {:?}", ty); + return Err(EvalError::TypeNotPrimitive(ty)); } }, - _ => bug!("primitive read of non-primitive type: {:?}", ty), + _ => return Err(EvalError::TypeNotPrimitive(ty)), }; Ok(kind)