about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2021-05-07 15:11:18 +0200
committerRalf Jung <post@ralfj.de>2021-05-07 15:13:23 +0200
commit4dddc3818ec6a618ba85a07ca4fdede56f7f0282 (patch)
tree9d8288ed24c717d27524235f1a89cb8f16a92f76 /compiler/rustc_middle/src/mir
parentac888e8675182c703c2cd097957878faf88dad94 (diff)
downloadrust-4dddc3818ec6a618ba85a07ca4fdede56f7f0282.tar.gz
rust-4dddc3818ec6a618ba85a07ca4fdede56f7f0282.zip
fix null pointer error messages
Diffstat (limited to 'compiler/rustc_middle/src/mir')
-rw-r--r--compiler/rustc_middle/src/mir/interpret/error.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs
index ea582d470f9..9c3bed6ec0a 100644
--- a/compiler/rustc_middle/src/mir/interpret/error.rs
+++ b/compiler/rustc_middle/src/mir/interpret/error.rs
@@ -170,22 +170,25 @@ impl fmt::Display for InvalidProgramInfo<'_> {
 /// Details of why a pointer had to be in-bounds.
 #[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
 pub enum CheckInAllocMsg {
+    /// We are access memory.
     MemoryAccessTest,
+    /// We are doing pointer arithmetic.
     PointerArithmeticTest,
+    /// None of the above -- generic/unspecific inbounds test.
     InboundsTest,
 }
 
 impl fmt::Display for CheckInAllocMsg {
     /// When this is printed as an error the context looks like this
-    /// "{test name} failed: pointer must be in-bounds at offset..."
+    /// "{msg}pointer must be in-bounds at offset..."
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(
             f,
             "{}",
             match *self {
-                CheckInAllocMsg::MemoryAccessTest => "memory access",
-                CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic",
-                CheckInAllocMsg::InboundsTest => "inbounds test",
+                CheckInAllocMsg::MemoryAccessTest => "memory access failed: ",
+                CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic failed: ",
+                CheckInAllocMsg::InboundsTest => "",
             }
         )
     }
@@ -299,18 +302,18 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
             }
             PointerOutOfBounds { ptr, msg, allocation_size } => write!(
                 f,
-                "{} failed: pointer must be in-bounds at offset {}, \
+                "{}pointer must be in-bounds at offset {}, \
                            but is outside bounds of {} which has size {}",
                 msg,
                 ptr.offset.bytes(),
                 ptr.alloc_id,
                 allocation_size.bytes()
             ),
-            DanglingIntPointer(_, CheckInAllocMsg::InboundsTest) => {
-                write!(f, "null pointer is not allowed for this operation")
+            DanglingIntPointer(0, CheckInAllocMsg::InboundsTest) => {
+                write!(f, "null pointer is not a valid pointer for this operation")
             }
             DanglingIntPointer(i, msg) => {
-                write!(f, "{} failed: 0x{:x} is not a valid pointer", msg, i)
+                write!(f, "{}0x{:x} is not a valid pointer", msg, i)
             }
             AlignmentCheckFailed { required, has } => write!(
                 f,