about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2021-07-15 20:07:01 +0200
committerRalf Jung <post@ralfj.de>2021-07-15 22:47:11 +0200
commit4e280656189588a3cc30b86599a0ff4f211030b8 (patch)
tree653d9dba7272d998a0018f2faf571b5a2524c107 /compiler/rustc_middle/src
parentbd874a9d5d59e32e7e1afb6c8bac4776dc55d4d1 (diff)
downloadrust-4e280656189588a3cc30b86599a0ff4f211030b8.tar.gz
rust-4e280656189588a3cc30b86599a0ff4f211030b8.zip
tweak pointer out-of-bounds error message
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/mir/interpret/error.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs
index 84241238276..432d078dc9b 100644
--- a/compiler/rustc_middle/src/mir/interpret/error.rs
+++ b/compiler/rustc_middle/src/mir/interpret/error.rs
@@ -181,8 +181,8 @@ pub enum CheckInAllocMsg {
 }
 
 impl fmt::Display for CheckInAllocMsg {
-    /// When this is printed as an error the context looks like this
-    /// "{msg}pointer must be in-bounds at offset..."
+    /// When this is printed as an error the context looks like this:
+    /// "{msg}0x01 is not a valid pointer".
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(
             f,
@@ -318,14 +318,24 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
             PointerUseAfterFree(a) => {
                 write!(f, "pointer to {} was dereferenced after this allocation got freed", a)
             }
+            PointerOutOfBounds { alloc_id, offset, size: Size::ZERO, msg, allocation_size } => {
+                write!(
+                    f,
+                    "{}{} has size {}, so pointer at offset {} is out-of-bounds",
+                    msg,
+                    alloc_id,
+                    allocation_size.bytes(),
+                    offset.bytes(),
+                )
+            }
             PointerOutOfBounds { alloc_id, offset, size, msg, allocation_size } => write!(
                 f,
-                "{}pointer must be in-bounds for {} bytes at offset {}, but {} has size {}",
+                "{}{} has size {}, so pointer to {} bytes starting at offset {} is out-of-bounds",
                 msg,
+                alloc_id,
+                allocation_size.bytes(),
                 size.bytes(),
                 offset.bytes(),
-                alloc_id,
-                allocation_size.bytes()
             ),
             DanglingIntPointer(0, CheckInAllocMsg::InboundsTest) => {
                 write!(f, "null pointer is not a valid pointer for this operation")