]> git.lizzy.rs Git - rust.git/commitdiff
provide a way to replace the tag in a Scalar/MemPlace
authorRalf Jung <post@ralfj.de>
Wed, 28 Nov 2018 08:22:02 +0000 (09:22 +0100)
committerRalf Jung <post@ralfj.de>
Mon, 3 Dec 2018 12:02:02 +0000 (13:02 +0100)
src/librustc/mir/interpret/value.rs
src/librustc_mir/interpret/place.rs

index 4bcba9d54674e3f7f610b59ab4bfaa2c26170b01..500bd47dfbe7e5b901bc699aff90d62d056f05cb 100644 (file)
@@ -138,6 +138,14 @@ pub fn erase_tag(self) -> Scalar {
         }
     }
 
+    #[inline]
+    pub fn with_tag(self, new_tag: Tag) -> Self {
+        match self {
+            Scalar::Ptr(ptr) => Scalar::Ptr(Pointer { tag: new_tag, ..ptr }),
+            Scalar::Bits { bits, size } => Scalar::Bits { bits, size },
+        }
+    }
+
     #[inline]
     pub fn ptr_null(cx: &impl HasDataLayout) -> Self {
         Scalar::Bits {
index 1b47530eaec65437065339102c8f736b4fdbc2ef..164a9680c797562e778b41b570d0fbeac8610680 100644 (file)
@@ -115,6 +115,16 @@ pub fn erase_tag(self) -> MemPlace
         }
     }
 
+    #[inline]
+    pub fn with_tag(self, new_tag: Tag) -> Self
+    {
+        MemPlace {
+            ptr: self.ptr.with_tag(new_tag),
+            align: self.align,
+            meta: self.meta,
+        }
+    }
+
     #[inline(always)]
     pub fn from_scalar_ptr(ptr: Scalar<Tag>, align: Align) -> Self {
         MemPlace {
@@ -187,6 +197,16 @@ pub fn dangling(layout: TyLayout<'tcx>, cx: &impl HasDataLayout) -> Self {
         }
     }
 
+    #[inline]
+    pub fn with_tag(self, new_tag: Tag) -> Self
+    {
+        MPlaceTy {
+            mplace: self.mplace.with_tag(new_tag),
+            layout: self.layout,
+        }
+    }
+
+    #[inline]
     pub fn offset(
         self,
         offset: Size,