]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #60959 - petrochenkov:sassert, r=estebank
authorMazdak Farrokhzad <twingoow@gmail.com>
Mon, 20 May 2019 21:03:07 +0000 (23:03 +0200)
committerGitHub <noreply@github.com>
Mon, 20 May 2019 21:03:07 +0000 (23:03 +0200)
rustc: Improve type size assertions

Now they
- Tell what the new size is, when it changes
- Do not require passing an identifier

```
   ::: src\libsyntax\parse\token.rs:223:1
    |
223 |    static_assert_size!(Token, 123);
    |    -------------------------------- in this macro invocation
    |
    = note: expected type `[(); 123]`
               found type `[(); 16]`
```

1  2 
src/librustc/hir/mod.rs
src/librustc/ty/mod.rs
src/librustc/ty/sty.rs

diff --combined src/librustc/hir/mod.rs
index 22312e7459be125af26df08568861237e5afa534,3ca79cb850128fe3b3dd9bd67f5187195ce6d696..57304c5ed37aec722b0f860cab48ff126235fb2f
@@@ -609,9 -609,9 +609,9 @@@ impl Generics 
          own_counts
      }
  
 -    pub fn get_named(&self, name: &InternedString) -> Option<&GenericParam> {
 +    pub fn get_named(&self, name: InternedString) -> Option<&GenericParam> {
          for param in &self.params {
 -            if *name == param.name.ident().as_interned_str() {
 +            if name == param.name.ident().as_interned_str() {
                  return Some(param);
              }
          }
@@@ -1356,7 -1356,7 +1356,7 @@@ pub struct Expr 
  
  // `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>() == 72);
+ static_assert_size!(Expr, 72);
  
  impl Expr {
      pub fn precedence(&self) -> ExprPrecedence {
diff --combined src/librustc/ty/mod.rs
index e1c432d5b6da14e9a805f630f4f282fd8fc7f612,1e4bb37c44ef13cbeedc9aec2f9cc19c3e12973d..91e996178e7d54904cbdde900e8524bf60d1f5da
@@@ -510,7 -510,7 +510,7 @@@ pub struct TyS<'tcx> 
  
  // `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);
+ static_assert_size!(TyS<'_>, 32);
  
  impl<'tcx> Ord for TyS<'tcx> {
      fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
@@@ -3405,7 -3405,7 +3405,7 @@@ impl_stable_hash_for!(struct self::Symb
  impl SymbolName {
      pub fn new(name: &str) -> SymbolName {
          SymbolName {
 -            name: Symbol::intern(name).as_interned_str()
 +            name: InternedString::intern(name)
          }
      }
  
diff --combined src/librustc/ty/sty.rs
index d20840ef7cf4de89d6118a99cbe29790e8bf3352,269064af93bc078beae1ab0f30124a0d24ce8591..e8f3bad4d3ee32832666fd66f72f4cc502707da8
@@@ -211,7 -211,7 +211,7 @@@ pub enum TyKind<'tcx> 
  
  // `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);
+ static_assert_size!(TyKind<'_>, 24);
  
  /// A closure can be modeled as a struct that looks like:
  ///
@@@ -1136,7 -1136,7 +1136,7 @@@ impl<'a, 'gcx, 'tcx> ParamTy 
          // FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere,
          // but this should only be possible when using `-Z continue-parse-after-error` like
          // `compile-fail/issue-36638.rs`.
 -        self.name == keywords::SelfUpper.name().as_str() && self.index == 0
 +        self.name.as_symbol() == keywords::SelfUpper.name() && self.index == 0
      }
  }
  
@@@ -2207,7 -2207,7 +2207,7 @@@ pub struct Const<'tcx> 
  }
  
  #[cfg(target_arch = "x86_64")]
- static_assert!(CONST_SIZE: ::std::mem::size_of::<Const<'static>>() == 48);
+ static_assert_size!(Const<'_>, 48);
  
  impl<'tcx> Const<'tcx> {
      #[inline]