From 7b4bc6974a16df46e5d50a1191c124fc8c1f56ae Mon Sep 17 00:00:00 2001 From: LooMaclin Date: Tue, 2 Apr 2019 06:16:11 +0300 Subject: [PATCH] Improve miri's error reporting in check_in_alloc --- src/librustc/mir/interpret/allocation.rs | 3 +-- src/librustc_mir/interpret/memory.rs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index f00da804e953..a04316b719e8 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -22,8 +22,7 @@ pub enum InboundsCheck { MaybeDead, } -/// Used by `check_in_alloc` to indicate whether the pointer needs to be just inbounds -/// or also inbounds of a *live* allocation. +/// Used by `check_in_alloc` to indicate context of check #[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum CheckInAllocMsg { ReadCStr, diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 302bc84e65c4..80efafa65503 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -20,7 +20,7 @@ use syntax::ast::Mutability; use super::{ Pointer, AllocId, Allocation, GlobalId, AllocationExtra, EvalResult, Scalar, EvalErrorKind, AllocKind, PointerArithmetic, - Machine, AllocMap, MayLeak, ErrorHandled, InboundsCheck, CheckInAllocMsg, + Machine, AllocMap, MayLeak, ErrorHandled, CheckInAllocMsg, }; #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)] @@ -440,13 +440,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { Ok((layout.size, layout.align.abi)) } _ => match msg { - InboundsCheck::MaybeDead => { + CheckInAllocMsg::CheckAlign | CheckInAllocMsg::ReadDiscriminant => { // Must be a deallocated pointer Ok(*self.dead_alloc_map.get(&id).expect( "allocation missing in dead_alloc_map" )) }, - InboundsCheck::Live => err!(DanglingPointerDeref), + _ => err!(DanglingPointerDeref), }, } }