Skip to content

Commit a14456f

Browse files
committed
Reduced the size of LintExpectationId by 12 bytes (RFC-2383)
1 parent 43dc430 commit a14456f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

compiler/rustc_lint/src/levels.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'s> LintLevelsBuilder<'s> {
312312
for (lint_index, li) in metas.iter_mut().enumerate() {
313313
let level = match level {
314314
Level::Expect(mut id) => {
315-
id.set_lint_index(Some(lint_index));
315+
id.set_lint_index(Some(lint_index as u16));
316316
Level::Expect(id)
317317
}
318318
level => level,
@@ -601,7 +601,8 @@ impl<'s> LintLevelsBuilder<'s> {
601601
hir_id: HirId,
602602
attr_index: usize,
603603
) -> LintExpectationId {
604-
let stable_id = LintExpectationId::Stable { hir_id, attr_index, lint_index: None };
604+
let stable_id =
605+
LintExpectationId::Stable { hir_id, attr_index: attr_index as u16, lint_index: None };
605606

606607
self.expectation_id_map.insert(unstable_id, stable_id);
607608

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,20 @@ pub enum Applicability {
6464
///
6565
/// Each lint inside the `expect` attribute is tracked individually, the `lint_index`
6666
/// identifies the lint inside the attribute and ensures that the IDs are unique.
67+
///
68+
/// The index values have a type of `u16` to reduce the size of the `LintExpectationId`.
69+
/// It's reasonable to assume that no user will define 2^16 attributes on one node or
70+
/// have that amount of lints listed. `u16` values should therefore suffice.
6771
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Encodable, Decodable)]
6872
pub enum LintExpectationId {
6973
/// Used for lints emitted during the `EarlyLintPass`. This id is not
7074
/// has stable and should not be cached.
71-
Unstable { attr_id: AttrId, lint_index: Option<usize> },
75+
Unstable { attr_id: AttrId, lint_index: Option<u16> },
7276
/// The [`HirId`] that the lint expectation is attached to. This id is
7377
/// stable and can be cached. The additional index ensures that nodes with
7478
/// several expectations can correctly match diagnostics to the individual
7579
/// expectation.
76-
Stable { hir_id: HirId, attr_index: usize, lint_index: Option<usize> },
80+
Stable { hir_id: HirId, attr_index: u16, lint_index: Option<u16> },
7781
}
7882

7983
impl LintExpectationId {
@@ -84,14 +88,14 @@ impl LintExpectationId {
8488
}
8589
}
8690

87-
pub fn get_lint_index(&self) -> Option<usize> {
91+
pub fn get_lint_index(&self) -> Option<u16> {
8892
let (LintExpectationId::Unstable { lint_index, .. }
8993
| LintExpectationId::Stable { lint_index, .. }) = self;
9094

9195
*lint_index
9296
}
9397

94-
pub fn set_lint_index(&mut self, new_lint_index: Option<usize>) {
98+
pub fn set_lint_index(&mut self, new_lint_index: Option<u16>) {
9599
let (LintExpectationId::Unstable { ref mut lint_index, .. }
96100
| LintExpectationId::Stable { ref mut lint_index, .. }) = self;
97101

@@ -116,7 +120,7 @@ impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
116120
}
117121

118122
impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
119-
type KeyType = (HirId, usize, usize);
123+
type KeyType = (HirId, u16, u16);
120124

121125
#[inline]
122126
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {

0 commit comments

Comments
 (0)