From fb3dd9f64ee9b34d6d0e25363ceda3a6ba9dcec3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 9 Nov 2018 10:10:46 +1100 Subject: Add a static assertion about the size of `ast::Expr`. --- src/libsyntax/ast.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2f17bc0548c..fa6fe347833 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -20,6 +20,7 @@ use print::pprust; use ptr::P; use rustc_data_structures::indexed_vec; use rustc_data_structures::indexed_vec::Idx; +use rustc_data_structures::static_assert; use rustc_target::spec::abi::Abi; use source_map::{dummy_spanned, respan, Spanned}; use symbol::{keywords, Symbol}; @@ -924,6 +925,10 @@ pub struct Expr { pub attrs: ThinVec, } +// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger. +#[cfg(target_arch = "x86_64")] +static_assert!(MEM_SIZE_OF_EXPR: std::mem::size_of::() == 88); + impl Expr { /// Whether this expression would be valid somewhere that expects a value, for example, an `if` /// condition. -- cgit 1.4.1-3-g733a5 From 2bd4d5b1a0b05827401970f0cfbe17e6b6f32d0d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 13 Nov 2018 06:34:11 +1100 Subject: Move two `static_assert!`s to better spots. And make them x86_64-only so they can use `==` instead of `<=`. --- src/librustc/ty/context.rs | 6 ------ src/librustc/ty/mod.rs | 4 ++++ src/librustc/ty/sty.rs | 4 ++++ src/libsyntax/ast.rs | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 82095a2f5b0..f78fad9f7aa 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -823,12 +823,6 @@ impl<'a, 'gcx> HashStable> for TypeckTables<'gcx> { impl<'tcx> CommonTypes<'tcx> { fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> { - // Ensure our type representation does not grow - #[cfg(target_pointer_width = "64")] - static_assert!(ASSERT_TY_KIND: ::std::mem::size_of::>() <= 24); - #[cfg(target_pointer_width = "64")] - static_assert!(ASSERT_TYS: ::std::mem::size_of::>() <= 32); - let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty); let mk_region = |r| { if let Some(r) = interners.region.borrow().get(&r) { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index ef9b3e3efab..32503426135 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -514,6 +514,10 @@ pub struct TyS<'tcx> { outer_exclusive_binder: ty::DebruijnIndex, } +// `TyS` is used a lot. Make sure it doesn't unintentionally get bigger. +#[cfg(target_arch = "x86_64")] +static_assert!(MEM_SIZE_OF_TY_S: ::std::mem::size_of::>() == 32); + impl<'tcx> Ord for TyS<'tcx> { fn cmp(&self, other: &TyS<'tcx>) -> Ordering { self.sty.cmp(&other.sty) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index a4130bf15cb..bd3a34cae90 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -211,6 +211,10 @@ pub enum TyKind<'tcx> { Error, } +// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger. +#[cfg(target_arch = "x86_64")] +static_assert!(MEM_SIZE_OF_TY_KIND: ::std::mem::size_of::>() == 24); + /// A closure can be modeled as a struct that looks like: /// /// struct Closure<'l0...'li, T0...Tj, CK, CS, U0...Uk> { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index fa6fe347833..808e19d6f12 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -20,6 +20,7 @@ use print::pprust; use ptr::P; use rustc_data_structures::indexed_vec; use rustc_data_structures::indexed_vec::Idx; +#[cfg(target_arch = "x86_64")] use rustc_data_structures::static_assert; use rustc_target::spec::abi::Abi; use source_map::{dummy_spanned, respan, Spanned}; -- cgit 1.4.1-3-g733a5