3 use rustc::mir::repr as mir;
6 #[derive(Clone, Debug)]
14 allocation_size: usize,
20 InvalidBoolOp(mir::BinOp),
21 Unimplemented(String),
24 pub type EvalResult<T> = Result<T, EvalError>;
26 impl Error for EvalError {
27 fn description(&self) -> &str {
29 EvalError::DanglingPointerDeref =>
30 "dangling pointer was dereferenced",
31 EvalError::InvalidBool =>
32 "invalid boolean value read",
33 EvalError::InvalidDiscriminant =>
34 "invalid enum discriminant value read",
35 EvalError::PointerOutOfBounds { .. } =>
36 "pointer offset outside bounds of allocation",
37 EvalError::ReadPointerAsBytes =>
38 "a raw memory access tried to access part of a pointer value as raw bytes",
39 EvalError::ReadBytesAsPointer =>
40 "attempted to interpret some raw bytes as a pointer address",
41 EvalError::InvalidPointerMath =>
42 "attempted to do math or a comparison on pointers into different allocations",
43 EvalError::ReadUndefBytes =>
44 "attempted to read undefined bytes",
45 EvalError::InvalidBoolOp(_) =>
46 "invalid boolean operation",
47 EvalError::Unimplemented(ref msg) => msg,
51 fn cause(&self) -> Option<&Error> { None }
54 impl fmt::Display for EvalError {
55 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57 EvalError::PointerOutOfBounds { ptr, size, allocation_size } => {
58 write!(f, "memory access of {}..{} outside bounds of allocation {} which has size {}",
59 ptr.offset, ptr.offset + size, ptr.alloc_id, allocation_size)
61 _ => write!(f, "{}", self.description()),