From 2a1748834e80b2461be4e18d420503d60e687312 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 8 Jan 2019 12:40:25 +0100 Subject: [PATCH] Add some size assertions for const eval types --- src/librustc/mir/interpret/pointer.rs | 2 ++ src/librustc/mir/interpret/value.rs | 6 ++++++ src/librustc/ty/sty.rs | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index a046825f088..498c0b5b917 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -76,6 +76,8 @@ pub struct Pointer { pub tag: Tag, } +static_assert!(POINTER_SIZE: ::std::mem::size_of::() == 16); + /// Produces a `Pointer` which points to the beginning of the Allocation impl From for Pointer { #[inline(always)] diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 76eb43e73d1..896e2ab960c 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -32,6 +32,9 @@ pub enum ConstValue<'tcx> { ByRef(AllocId, &'tcx Allocation, Size), } +#[cfg(target_arch = "x86_64")] +static_assert!(CONST_SIZE: ::std::mem::size_of::>() == 56); + impl<'tcx> ConstValue<'tcx> { #[inline] pub fn try_to_scalar(&self) -> Option { @@ -90,6 +93,9 @@ pub enum Scalar { Ptr(Pointer), } +#[cfg(target_arch = "x86_64")] +static_assert!(SCALAR_SIZE: ::std::mem::size_of::() == 24); + impl fmt::Display for Scalar { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index b98369b62ea..a42b80e594c 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -2063,6 +2063,9 @@ pub enum LazyConst<'tcx> { Evaluated(Const<'tcx>), } +#[cfg(target_arch = "x86_64")] +static_assert!(LAZY_CONST_SIZE: ::std::mem::size_of::>() == 72); + impl<'tcx> LazyConst<'tcx> { pub fn map_evaluated(self, f: impl FnOnce(Const<'tcx>) -> Option) -> Option { match self { @@ -2089,6 +2092,9 @@ pub struct Const<'tcx> { pub val: ConstValue<'tcx>, } +#[cfg(target_arch = "x86_64")] +static_assert!(CONST_SIZE: ::std::mem::size_of::>() == 64); + impl<'tcx> Const<'tcx> { #[inline] pub fn from_scalar(