diff options
| author | Ralf Jung <post@ralfj.de> | 2020-04-04 13:34:18 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-04-04 13:45:22 +0200 |
| commit | 1f3e2478b2e7267034d30a76ef4d28791a57d925 (patch) | |
| tree | d4588abe02a3148ebf712ab9b7eaa54f8e950756 | |
| parent | aecaeab5ec47ca34da95b4730cbfe80a19ce6fe6 (diff) | |
indicate better which kind of memory got leaked
| -rw-r--r-- | src/librustc_mir/interpret/machine.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 26 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 8875baad58c..23e39f433f5 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -79,7 +79,7 @@ pub trait AllocMap<K: Hash + Eq, V> { /// and some use case dependent behaviour can instead be applied. pub trait Machine<'mir, 'tcx>: Sized { /// Additional memory kinds a machine wishes to distinguish from the builtin ones - type MemoryKind: ::std::fmt::Debug + MayLeak + Eq + 'static; + type MemoryKind: ::std::fmt::Debug + ::std::fmt::Display + MayLeak + Eq + 'static; /// Tag tracked alongside every pointer. This is used to implement "Stacked Borrows" /// <https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html>. diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index e61b0796cc1..c16c59715e4 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -9,6 +9,7 @@ use std::borrow::Cow; use std::collections::VecDeque; use std::convert::TryFrom; +use std::fmt; use std::ptr; use rustc_ast::ast::Mutability; @@ -46,6 +47,17 @@ impl<T: MayLeak> MayLeak for MemoryKind<T> { } } +impl<T: fmt::Display> fmt::Display for MemoryKind<T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + MemoryKind::Stack => write!(f, "stack variable"), + MemoryKind::Vtable => write!(f, "vtable"), + MemoryKind::CallerLocation => write!(f, "caller location"), + MemoryKind::Machine(m) => write!(f, "{}", m), + } + } +} + /// Used by `get_size_and_align` to indicate whether the allocation needs to be live. #[derive(Debug, Copy, Clone)] pub enum AllocCheck { @@ -259,7 +271,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { if alloc_kind != kind { throw_ub_format!( - "deallocating `{:?}` memory using `{:?}` deallocation operation", + "deallocating {} memory using {} deallocation operation", alloc_kind, kind ); @@ -677,22 +689,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { match self.alloc_map.get(id) { Some(&(kind, ref alloc)) => { // normal alloc - match kind { - MemoryKind::Stack => eprint!(" (stack variable, "), - MemoryKind::Vtable => eprint!(" (vtable, "), - MemoryKind::CallerLocation => eprint!(" (caller_location, "), - MemoryKind::Machine(m) if Some(m) == M::GLOBAL_KIND => { - eprint!(" (global, ") - } - MemoryKind::Machine(m) => eprint!(" ({:?}, ", m), - }; + eprint!(" ({}, ", kind); write_allocation_track_relocs(self.tcx, &mut allocs_to_print, alloc); } None => { // global alloc match self.tcx.alloc_map.lock().get(id) { Some(GlobalAlloc::Memory(alloc)) => { - eprint!(" (global, "); + eprint!(" (unchanged global, "); write_allocation_track_relocs(self.tcx, &mut allocs_to_print, alloc); } Some(GlobalAlloc::Function(func)) => { |
