about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/interpret/pointer.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2021-07-16 09:39:35 +0200
committerRalf Jung <post@ralfj.de>2021-07-16 10:09:56 +0200
commit7c720ce6121dd878b25f8e6a645a07563e5a4b01 (patch)
tree1aa40698e47dde0b95b0d78522fb8839f8e0c54c /compiler/rustc_middle/src/mir/interpret/pointer.rs
parent4e280656189588a3cc30b86599a0ff4f211030b8 (diff)
downloadrust-7c720ce6121dd878b25f8e6a645a07563e5a4b01.tar.gz
rust-7c720ce6121dd878b25f8e6a645a07563e5a4b01.zip
get rid of incorrect erase_for_fmt
Diffstat (limited to 'compiler/rustc_middle/src/mir/interpret/pointer.rs')
-rw-r--r--compiler/rustc_middle/src/mir/interpret/pointer.rs26
1 files changed, 5 insertions, 21 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/pointer.rs b/compiler/rustc_middle/src/mir/interpret/pointer.rs
index 307d7d28462..c7daaec8d5d 100644
--- a/compiler/rustc_middle/src/mir/interpret/pointer.rs
+++ b/compiler/rustc_middle/src/mir/interpret/pointer.rs
@@ -89,7 +89,7 @@ impl<T: HasDataLayout> PointerArithmetic for T {}
 pub trait Provenance: Copy {
     /// Says whether the `offset` field of `Pointer`s with this provenance is the actual physical address.
     /// If `true, ptr-to-int casts work by simply discarding the provenance.
-    /// If `false`, ptr-to-int casts are not supported.
+    /// If `false`, ptr-to-int casts are not supported. The offset *must* be relative in that case.
     const OFFSET_IS_ADDR: bool;
 
     /// Determines how a pointer should be printed.
@@ -97,8 +97,9 @@ pub trait Provenance: Copy {
     where
         Self: Sized;
 
-    /// "Erasing" a tag converts it to the default tag type if possible. Used only for formatting purposes!
-    fn erase_for_fmt(self) -> AllocId;
+    /// Provenance must always be able to identify the allocation this ptr points to.
+    /// (Identifying the offset in that allocation, however, is harder -- use `Memory::ptr_get_alloc` for that.)
+    fn get_alloc_id(self) -> AllocId;
 }
 
 impl Provenance for AllocId {
@@ -120,7 +121,7 @@ impl Provenance for AllocId {
         Ok(())
     }
 
-    fn erase_for_fmt(self) -> AllocId {
+    fn get_alloc_id(self) -> AllocId {
         self
     }
 }
@@ -177,14 +178,6 @@ impl<Tag> Pointer<Option<Tag>> {
             None => Err(self.offset),
         }
     }
-
-    #[inline(always)]
-    pub fn map_erase_for_fmt(self) -> Pointer<Option<AllocId>>
-    where
-        Tag: Provenance,
-    {
-        Pointer { offset: self.offset, provenance: self.provenance.map(Provenance::erase_for_fmt) }
-    }
 }
 
 impl<Tag> Pointer<Option<Tag>> {
@@ -208,15 +201,6 @@ impl<'tcx, Tag> Pointer<Tag> {
         (self.provenance, self.offset)
     }
 
-    #[inline(always)]
-    pub fn erase_for_fmt(self) -> Pointer
-    where
-        Tag: Provenance,
-    {
-        // FIXME: This is wrong! `self.offset` might be an absolute address.
-        Pointer { offset: self.offset, provenance: self.provenance.erase_for_fmt() }
-    }
-
     pub fn map_provenance(self, f: impl FnOnce(Tag) -> Tag) -> Self {
         Pointer { provenance: f(self.provenance), ..self }
     }