diff options
| author | Ralf Jung <post@ralfj.de> | 2018-11-28 09:22:02 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2018-12-03 13:02:02 +0100 |
| commit | 005df5fe03ba2f9cdb7ed58d7cfb2c194184cc28 (patch) | |
| tree | 6c2e4b857f7397c4d6c20fd1909c1839b8c16c52 /src | |
| parent | d2c19e0bcc2c11e83187dcfc48f9fa110ecf2318 (diff) | |
| download | rust-005df5fe03ba2f9cdb7ed58d7cfb2c194184cc28.tar.gz rust-005df5fe03ba2f9cdb7ed58d7cfb2c194184cc28.zip | |
provide a way to replace the tag in a Scalar/MemPlace
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/mir/interpret/value.rs | 8 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/place.rs | 20 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 4bcba9d5467..500bd47dfbe 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -139,6 +139,14 @@ impl<'tcx, Tag> Scalar<Tag> { } #[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 { bits: 0, diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 1b47530eaec..164a9680c79 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -115,6 +115,16 @@ impl<Tag> MemPlace<Tag> { } } + #[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 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { } } + #[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, |
