Skip to content

Commit 005df5f

Browse files
committed
provide a way to replace the tag in a Scalar/MemPlace
1 parent d2c19e0 commit 005df5f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/librustc/mir/interpret/value.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ impl<'tcx, Tag> Scalar<Tag> {
138138
}
139139
}
140140

141+
#[inline]
142+
pub fn with_tag(self, new_tag: Tag) -> Self {
143+
match self {
144+
Scalar::Ptr(ptr) => Scalar::Ptr(Pointer { tag: new_tag, ..ptr }),
145+
Scalar::Bits { bits, size } => Scalar::Bits { bits, size },
146+
}
147+
}
148+
141149
#[inline]
142150
pub fn ptr_null(cx: &impl HasDataLayout) -> Self {
143151
Scalar::Bits {

src/librustc_mir/interpret/place.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ impl<Tag> MemPlace<Tag> {
115115
}
116116
}
117117

118+
#[inline]
119+
pub fn with_tag(self, new_tag: Tag) -> Self
120+
{
121+
MemPlace {
122+
ptr: self.ptr.with_tag(new_tag),
123+
align: self.align,
124+
meta: self.meta,
125+
}
126+
}
127+
118128
#[inline(always)]
119129
pub fn from_scalar_ptr(ptr: Scalar<Tag>, align: Align) -> Self {
120130
MemPlace {
@@ -187,6 +197,16 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
187197
}
188198
}
189199

200+
#[inline]
201+
pub fn with_tag(self, new_tag: Tag) -> Self
202+
{
203+
MPlaceTy {
204+
mplace: self.mplace.with_tag(new_tag),
205+
layout: self.layout,
206+
}
207+
}
208+
209+
#[inline]
190210
pub fn offset(
191211
self,
192212
offset: Size,

0 commit comments

Comments
 (0)