Skip to content

Commit eaf1c7a

Browse files
authored
Rollup merge of #102493 - nnethercote:improve-size-assertions-some-more, r=lqd
Group together more size assertions. Also add a few more assertions for some relevant token-related types. And fix an erroneous comment in `rustc_errors`. r? `@lqd`
2 parents 842a7d3 + 5ab68a8 commit eaf1c7a

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

compiler/rustc_ast/src/token.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ pub enum TokenKind {
256256
Eof,
257257
}
258258

259-
// `TokenKind` is used a lot. Make sure it doesn't unintentionally get bigger.
260-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
261-
rustc_data_structures::static_assert_size!(TokenKind, 16);
262-
263259
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
264260
pub struct Token {
265261
pub kind: TokenKind,
@@ -752,10 +748,6 @@ pub enum Nonterminal {
752748
NtVis(P<ast::Visibility>),
753749
}
754750

755-
// `Nonterminal` is used a lot. Make sure it doesn't unintentionally get bigger.
756-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
757-
rustc_data_structures::static_assert_size!(Nonterminal, 16);
758-
759751
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable)]
760752
pub enum NonterminalKind {
761753
Item,
@@ -894,3 +886,16 @@ where
894886
panic!("interpolated tokens should not be present in the HIR")
895887
}
896888
}
889+
890+
// Some types are used a lot. Make sure they don't unintentionally get bigger.
891+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
892+
mod size_asserts {
893+
use super::*;
894+
use rustc_data_structures::static_assert_size;
895+
// These are in alphabetical order, which is easy to maintain.
896+
static_assert_size!(Lit, 12);
897+
static_assert_size!(LitKind, 2);
898+
static_assert_size!(Nonterminal, 16);
899+
static_assert_size!(Token, 24);
900+
static_assert_size!(TokenKind, 16);
901+
}

compiler/rustc_ast/src/tokenstream.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ pub enum TokenTree {
4747
Delimited(DelimSpan, Delimiter, TokenStream),
4848
}
4949

50-
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
51-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
52-
rustc_data_structures::static_assert_size!(TokenTree, 32);
53-
5450
// Ensure all fields of `TokenTree` is `Send` and `Sync`.
5551
#[cfg(parallel_compiler)]
5652
fn _dummy()
@@ -308,10 +304,6 @@ pub struct AttributesData {
308304
#[derive(Clone, Debug, Default, Encodable, Decodable)]
309305
pub struct TokenStream(pub(crate) Lrc<Vec<TokenTree>>);
310306

311-
// `TokenStream` is used a lot. Make sure it doesn't unintentionally get bigger.
312-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
313-
rustc_data_structures::static_assert_size!(TokenStream, 8);
314-
315307
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
316308
pub enum Spacing {
317309
Alone,
@@ -664,3 +656,16 @@ impl DelimSpan {
664656
self.open.with_hi(self.close.hi())
665657
}
666658
}
659+
660+
// Some types are used a lot. Make sure they don't unintentionally get bigger.
661+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
662+
mod size_asserts {
663+
use super::*;
664+
use rustc_data_structures::static_assert_size;
665+
// These are in alphabetical order, which is easy to maintain.
666+
static_assert_size!(AttrTokenStream, 8);
667+
static_assert_size!(AttrTokenTree, 32);
668+
static_assert_size!(LazyAttrTokenStream, 8);
669+
static_assert_size!(TokenStream, 8);
670+
static_assert_size!(TokenTree, 32);
671+
}

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub type PErr<'a> = DiagnosticBuilder<'a, ErrorGuaranteed>;
6666
pub type PResult<'a, T> = Result<T, PErr<'a>>;
6767

6868
// `PResult` is used a lot. Make sure it doesn't unintentionally get bigger.
69-
// (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.)
69+
// (See also the comment on `DiagnosticBuilderInner`'s `diagnostic` field.)
7070
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
7171
rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16);
7272
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]

compiler/rustc_parse/src/parser/attr_wrapper.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ pub struct AttrWrapper {
3232
start_pos: usize,
3333
}
3434

35-
// This struct is passed around very frequently,
36-
// so make sure it doesn't accidentally get larger
37-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
38-
rustc_data_structures::static_assert_size!(AttrWrapper, 16);
39-
4035
impl AttrWrapper {
4136
pub(super) fn new(attrs: AttrVec, start_pos: usize) -> AttrWrapper {
4237
AttrWrapper { attrs, start_pos }
@@ -96,9 +91,6 @@ struct LazyAttrTokenStreamImpl {
9691
replace_ranges: Box<[ReplaceRange]>,
9792
}
9893

99-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
100-
rustc_data_structures::static_assert_size!(LazyAttrTokenStreamImpl, 144);
101-
10294
impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
10395
fn to_attr_token_stream(&self) -> AttrTokenStream {
10496
// The token produced by the final call to `{,inlined_}next` was not
@@ -461,3 +453,13 @@ fn make_token_stream(
461453
}
462454
AttrTokenStream::new(final_buf.inner)
463455
}
456+
457+
// Some types are used a lot. Make sure they don't unintentionally get bigger.
458+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
459+
mod size_asserts {
460+
use super::*;
461+
use rustc_data_structures::static_assert_size;
462+
// These are in alphabetical order, which is easy to maintain.
463+
static_assert_size!(AttrWrapper, 16);
464+
static_assert_size!(LazyAttrTokenStreamImpl, 144);
465+
}

0 commit comments

Comments
 (0)