mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 22:46:50 +00:00
Rollup merge of #55805 - nnethercote:mv-static_assert, r=Mark-Simulacrum
Move `static_assert!` into librustc_data_structures
This commit is contained in:
commit
98bc7d63fb
@ -62,16 +62,6 @@ macro_rules! span_bug {
|
||||
})
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! static_assert {
|
||||
($name:ident: $test:expr) => {
|
||||
// Use the bool to access an array such that if the bool is false, the access
|
||||
// is out-of-bounds.
|
||||
#[allow(dead_code)]
|
||||
static $name: () = [()][!$test as usize];
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! __impl_stable_hash_field {
|
||||
($field:ident, $ctx:expr, $hasher:expr) => ($field.hash_stable($ctx, $hasher));
|
||||
|
@ -1719,14 +1719,14 @@ pub struct Statement<'tcx> {
|
||||
pub kind: StatementKind<'tcx>,
|
||||
}
|
||||
|
||||
// `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
static_assert!(MEM_SIZE_OF_STATEMENT: mem::size_of::<Statement<'_>>() == 56);
|
||||
|
||||
impl<'tcx> Statement<'tcx> {
|
||||
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
|
||||
/// invalidating statement indices in `Location`s.
|
||||
pub fn make_nop(&mut self) {
|
||||
// `Statement` contributes significantly to peak memory usage. Make
|
||||
// sure it doesn't get bigger.
|
||||
static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56);
|
||||
|
||||
self.kind = StatementKind::Nop
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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> {
|
||||
|
@ -57,6 +57,7 @@ extern crate rustc_cratesio_shim;
|
||||
|
||||
pub use rustc_serialize::hex::ToHex;
|
||||
|
||||
pub mod macros;
|
||||
pub mod svh;
|
||||
pub mod base_n;
|
||||
pub mod bit_set;
|
||||
|
21
src/librustc_data_structures/macros.rs
Normal file
21
src/librustc_data_structures/macros.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
/// A simple static assertion macro. The first argument should be a unique
|
||||
/// ALL_CAPS identifier that describes the condition.
|
||||
#[macro_export]
|
||||
macro_rules! static_assert {
|
||||
($name:ident: $test:expr) => {
|
||||
// Use the bool to access an array such that if the bool is false, the access
|
||||
// is out-of-bounds.
|
||||
#[allow(dead_code)]
|
||||
static $name: () = [()][!$test as usize];
|
||||
}
|
||||
}
|
@ -20,6 +20,8 @@ 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};
|
||||
use symbol::{keywords, Symbol};
|
||||
@ -924,6 +926,10 @@ pub struct Expr {
|
||||
pub attrs: ThinVec<Attribute>,
|
||||
}
|
||||
|
||||
// `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::<Expr>() == 88);
|
||||
|
||||
impl Expr {
|
||||
/// Whether this expression would be valid somewhere that expects a value, for example, an `if`
|
||||
/// condition.
|
||||
|
Loading…
Reference in New Issue
Block a user