Reduced the size of LintExpectationId
by 12 bytes (RFC-2383)
This commit is contained in:
parent
43dc430f52
commit
a14456f91f
2 changed files with 12 additions and 7 deletions
|
@ -312,7 +312,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
for (lint_index, li) in metas.iter_mut().enumerate() {
|
for (lint_index, li) in metas.iter_mut().enumerate() {
|
||||||
let level = match level {
|
let level = match level {
|
||||||
Level::Expect(mut id) => {
|
Level::Expect(mut id) => {
|
||||||
id.set_lint_index(Some(lint_index));
|
id.set_lint_index(Some(lint_index as u16));
|
||||||
Level::Expect(id)
|
Level::Expect(id)
|
||||||
}
|
}
|
||||||
level => level,
|
level => level,
|
||||||
|
@ -601,7 +601,8 @@ impl<'s> LintLevelsBuilder<'s> {
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
attr_index: usize,
|
attr_index: usize,
|
||||||
) -> LintExpectationId {
|
) -> LintExpectationId {
|
||||||
let stable_id = LintExpectationId::Stable { hir_id, attr_index, lint_index: None };
|
let stable_id =
|
||||||
|
LintExpectationId::Stable { hir_id, attr_index: attr_index as u16, lint_index: None };
|
||||||
|
|
||||||
self.expectation_id_map.insert(unstable_id, stable_id);
|
self.expectation_id_map.insert(unstable_id, stable_id);
|
||||||
|
|
||||||
|
|
|
@ -64,16 +64,20 @@ pub enum Applicability {
|
||||||
///
|
///
|
||||||
/// Each lint inside the `expect` attribute is tracked individually, the `lint_index`
|
/// Each lint inside the `expect` attribute is tracked individually, the `lint_index`
|
||||||
/// identifies the lint inside the attribute and ensures that the IDs are unique.
|
/// identifies the lint inside the attribute and ensures that the IDs are unique.
|
||||||
|
///
|
||||||
|
/// The index values have a type of `u16` to reduce the size of the `LintExpectationId`.
|
||||||
|
/// It's reasonable to assume that no user will define 2^16 attributes on one node or
|
||||||
|
/// have that amount of lints listed. `u16` values should therefore suffice.
|
||||||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Encodable, Decodable)]
|
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Encodable, Decodable)]
|
||||||
pub enum LintExpectationId {
|
pub enum LintExpectationId {
|
||||||
/// Used for lints emitted during the `EarlyLintPass`. This id is not
|
/// Used for lints emitted during the `EarlyLintPass`. This id is not
|
||||||
/// has stable and should not be cached.
|
/// has stable and should not be cached.
|
||||||
Unstable { attr_id: AttrId, lint_index: Option<usize> },
|
Unstable { attr_id: AttrId, lint_index: Option<u16> },
|
||||||
/// The [`HirId`] that the lint expectation is attached to. This id is
|
/// The [`HirId`] that the lint expectation is attached to. This id is
|
||||||
/// stable and can be cached. The additional index ensures that nodes with
|
/// stable and can be cached. The additional index ensures that nodes with
|
||||||
/// several expectations can correctly match diagnostics to the individual
|
/// several expectations can correctly match diagnostics to the individual
|
||||||
/// expectation.
|
/// expectation.
|
||||||
Stable { hir_id: HirId, attr_index: usize, lint_index: Option<usize> },
|
Stable { hir_id: HirId, attr_index: u16, lint_index: Option<u16> },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintExpectationId {
|
impl LintExpectationId {
|
||||||
|
@ -84,14 +88,14 @@ impl LintExpectationId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_lint_index(&self) -> Option<usize> {
|
pub fn get_lint_index(&self) -> Option<u16> {
|
||||||
let (LintExpectationId::Unstable { lint_index, .. }
|
let (LintExpectationId::Unstable { lint_index, .. }
|
||||||
| LintExpectationId::Stable { lint_index, .. }) = self;
|
| LintExpectationId::Stable { lint_index, .. }) = self;
|
||||||
|
|
||||||
*lint_index
|
*lint_index
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_lint_index(&mut self, new_lint_index: Option<usize>) {
|
pub fn set_lint_index(&mut self, new_lint_index: Option<u16>) {
|
||||||
let (LintExpectationId::Unstable { ref mut lint_index, .. }
|
let (LintExpectationId::Unstable { ref mut lint_index, .. }
|
||||||
| LintExpectationId::Stable { ref mut lint_index, .. }) = self;
|
| LintExpectationId::Stable { ref mut lint_index, .. }) = self;
|
||||||
|
|
||||||
|
@ -116,7 +120,7 @@ impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
|
impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
|
||||||
type KeyType = (HirId, usize, usize);
|
type KeyType = (HirId, u16, u16);
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
|
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue