Skip to content

Commit 2a17488

Browse files
committed
Add some size assertions for const eval types
1 parent 1578955 commit 2a17488

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/librustc/mir/interpret/pointer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pub struct Pointer<Tag=(),Id=AllocId> {
7676
pub tag: Tag,
7777
}
7878

79+
static_assert!(POINTER_SIZE: ::std::mem::size_of::<Pointer>() == 16);
80+
7981
/// Produces a `Pointer` which points to the beginning of the Allocation
8082
impl From<AllocId> for Pointer {
8183
#[inline(always)]

src/librustc/mir/interpret/value.rs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub enum ConstValue<'tcx> {
3232
ByRef(AllocId, &'tcx Allocation, Size),
3333
}
3434

35+
#[cfg(target_arch = "x86_64")]
36+
static_assert!(CONST_SIZE: ::std::mem::size_of::<ConstValue<'static>>() == 56);
37+
3538
impl<'tcx> ConstValue<'tcx> {
3639
#[inline]
3740
pub fn try_to_scalar(&self) -> Option<Scalar> {
@@ -90,6 +93,9 @@ pub enum Scalar<Tag=(), Id=AllocId> {
9093
Ptr(Pointer<Tag, Id>),
9194
}
9295

96+
#[cfg(target_arch = "x86_64")]
97+
static_assert!(SCALAR_SIZE: ::std::mem::size_of::<Scalar>() == 24);
98+
9399
impl<Tag> fmt::Display for Scalar<Tag> {
94100
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95101
match self {

src/librustc/ty/sty.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,9 @@ pub enum LazyConst<'tcx> {
20632063
Evaluated(Const<'tcx>),
20642064
}
20652065

2066+
#[cfg(target_arch = "x86_64")]
2067+
static_assert!(LAZY_CONST_SIZE: ::std::mem::size_of::<LazyConst<'static>>() == 72);
2068+
20662069
impl<'tcx> LazyConst<'tcx> {
20672070
pub fn map_evaluated<R>(self, f: impl FnOnce(Const<'tcx>) -> Option<R>) -> Option<R> {
20682071
match self {
@@ -2089,6 +2092,9 @@ pub struct Const<'tcx> {
20892092
pub val: ConstValue<'tcx>,
20902093
}
20912094

2095+
#[cfg(target_arch = "x86_64")]
2096+
static_assert!(CONST_SIZE: ::std::mem::size_of::<Const<'static>>() == 64);
2097+
20922098
impl<'tcx> Const<'tcx> {
20932099
#[inline]
20942100
pub fn from_scalar(

0 commit comments

Comments
 (0)