]> git.lizzy.rs Git - rust.git/blobdiff - src/error.rs
improve out of bounds error message
[rust.git] / src / error.rs
index c82b7fa1ca61a740bc57e4cd402288d0376306ac..7d252658ba2d69d655335474c811d157f543d056 100644 (file)
@@ -1,6 +1,7 @@
 use std::error::Error;
 use std::fmt;
 use rustc::mir::repr as mir;
+use memory::Pointer;
 
 #[derive(Clone, Debug)]
 pub enum EvalError {
@@ -8,9 +9,9 @@ pub enum EvalError {
     InvalidBool,
     InvalidDiscriminant,
     PointerOutOfBounds {
-        offset: usize,
+        ptr: Pointer,
         size: usize,
-        len: usize,
+        allocation_size: usize,
     },
     ReadPointerAsBytes,
     ReadBytesAsPointer,
@@ -53,7 +54,10 @@ fn cause(&self) -> Option<&Error> { None }
 impl fmt::Display for EvalError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
-            EvalError::PointerOutOfBounds { offset, size, len } => write!(f, "pointer offset ({} + {}) outside bounds ({}) of allocation", offset, size, len),
+            EvalError::PointerOutOfBounds { ptr, size, allocation_size } => {
+                write!(f, "memory access of {}..{} outside bounds of allocation {} which has size {}",
+                       ptr.offset, ptr.offset + size, ptr.alloc_id, allocation_size)
+            },
             _ => write!(f, "{}", self.description()),
         }
     }