Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move two static_assert!s to better spots.
And make them x86_64-only so they can use `==` instead of `<=`.
  • Loading branch information
nnethercote committed Nov 13, 2018
1 parent fb3dd9f commit 2bd4d5b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/librustc/ty/context.rs
Expand Up @@ -823,12 +823,6 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> 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::<ty::TyKind<'_>>() <= 24);
#[cfg(target_pointer_width = "64")]
static_assert!(ASSERT_TYS: ::std::mem::size_of::<ty::TyS<'_>>() <= 32);

let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
let mk_region = |r| {
if let Some(r) = interners.region.borrow().get(&r) {
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/ty/mod.rs
Expand Up @@ -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::<TyS<'_>>() == 32);

impl<'tcx> Ord for TyS<'tcx> {
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
self.sty.cmp(&other.sty)
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/ty/sty.rs
Expand Up @@ -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::<TyKind<'_>>() == 24);

/// A closure can be modeled as a struct that looks like:
///
/// struct Closure<'l0...'li, T0...Tj, CK, CS, U0...Uk> {
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ast.rs
Expand Up @@ -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};
Expand Down

0 comments on commit 2bd4d5b

Please sign in to comment.