Skip to content

Commit 5f1f45b

Browse files
committed
Remove attr_id from stable lint ids.
1 parent 111b0a9 commit 5f1f45b

File tree

5 files changed

+14
-42
lines changed

5 files changed

+14
-42
lines changed

compiler/rustc_errors/src/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl DiagInner {
368368
panic!("{expectation_id:?} must have a matching stable id")
369369
};
370370

371-
let mut stable_id = stable_id.normalize();
371+
let mut stable_id = *stable_id;
372372
stable_id.set_lint_index(lint_index);
373373
*expectation_id = stable_id;
374374
}

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ impl DiagCtxtInner {
15671567
if let LintExpectationId::Unstable { .. } = expect_id {
15681568
unreachable!(); // this case was handled at the top of this function
15691569
}
1570-
self.fulfilled_expectations.insert(expect_id.normalize());
1570+
self.fulfilled_expectations.insert(expect_id);
15711571
if let Expect(_) = diagnostic.level {
15721572
// Nothing emitted here for expected lints.
15731573
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);

compiler/rustc_lint/src/expect.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
2020
let mut unstable_to_stable_ids = FxIndexMap::default();
2121

2222
let mut record_stable = |attr_id, hir_id, attr_index| {
23-
let expect_id =
24-
LintExpectationId::Stable { hir_id, attr_index, lint_index: None, attr_id: None };
23+
let expect_id = LintExpectationId::Stable { hir_id, attr_index, lint_index: None };
2524
unstable_to_stable_ids.entry(attr_id).or_insert(expect_id);
2625
};
2726
let mut push_expectations = |owner| {

compiler/rustc_lint/src/levels.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
218218
self.specs.lint_level_id_at_node(self.tcx, LintId::of(lint), self.cur)
219219
}
220220
fn push_expectation(&mut self, id: LintExpectationId, expectation: LintExpectation) {
221-
self.specs.expectations.push((id.normalize(), expectation))
221+
self.specs.expectations.push((id, expectation))
222222
}
223223
}
224224

@@ -486,13 +486,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
486486
/// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
487487
/// (e.g. if a forbid was already inserted on the same scope), then emits a
488488
/// diagnostic with no change to `specs`.
489-
fn insert_spec(&mut self, id: LintId, (mut level, src): LevelAndSource) {
489+
fn insert_spec(&mut self, id: LintId, (level, src): LevelAndSource) {
490490
let (old_level, old_src) = self.provider.get_lint_level(id.lint, self.sess);
491-
if let Level::Expect(id) = &mut level
492-
&& let LintExpectationId::Stable { .. } = id
493-
{
494-
*id = id.normalize();
495-
}
491+
496492
// Setting to a non-forbid level is an error if the lint previously had
497493
// a forbid level. Note that this is not necessarily true even with a
498494
// `#[forbid(..)]` attribute present, as that is overridden by `--cap-lints`.
@@ -604,17 +600,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
604600
// This is the only lint level with a `LintExpectationId` that can be created from
605601
// an attribute.
606602
Some(Level::Expect(unstable_id)) if let Some(hir_id) = source_hir_id => {
607-
let LintExpectationId::Unstable { attr_id, lint_index } = unstable_id else {
603+
let LintExpectationId::Unstable { lint_index: None, attr_id: _ } = unstable_id
604+
else {
608605
bug!("stable id Level::from_attr")
609606
};
610607

611608
let stable_id = LintExpectationId::Stable {
612609
hir_id,
613610
attr_index: attr_index.try_into().unwrap(),
614-
lint_index,
615-
// We pass the previous unstable attr_id such that we can trace the ast id
616-
// when building a map to go from unstable to stable id.
617-
attr_id: Some(attr_id),
611+
lint_index: None,
618612
};
619613

620614
Level::Expect(stable_id)

compiler/rustc_lint_defs/src/lib.rs

+5-26
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub enum LintExpectationId {
9898
/// stable and can be cached. The additional index ensures that nodes with
9999
/// several expectations can correctly match diagnostics to the individual
100100
/// expectation.
101-
Stable { hir_id: HirId, attr_index: u16, lint_index: Option<u16>, attr_id: Option<AttrId> },
101+
Stable { hir_id: HirId, attr_index: u16, lint_index: Option<u16> },
102102
}
103103

104104
impl LintExpectationId {
@@ -122,31 +122,13 @@ impl LintExpectationId {
122122

123123
*lint_index = new_lint_index
124124
}
125-
126-
/// Prepares the id for hashing. Removes references to the ast.
127-
/// Should only be called when the id is stable.
128-
pub fn normalize(self) -> Self {
129-
match self {
130-
Self::Stable { hir_id, attr_index, lint_index, .. } => {
131-
Self::Stable { hir_id, attr_index, lint_index, attr_id: None }
132-
}
133-
Self::Unstable { .. } => {
134-
unreachable!("`normalize` called when `ExpectationId` is unstable")
135-
}
136-
}
137-
}
138125
}
139126

140127
impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
141128
#[inline]
142129
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
143130
match self {
144-
LintExpectationId::Stable {
145-
hir_id,
146-
attr_index,
147-
lint_index: Some(lint_index),
148-
attr_id: _,
149-
} => {
131+
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
150132
hir_id.hash_stable(hcx, hasher);
151133
attr_index.hash_stable(hcx, hasher);
152134
lint_index.hash_stable(hcx, hasher);
@@ -166,12 +148,9 @@ impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectation
166148
#[inline]
167149
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
168150
match self {
169-
LintExpectationId::Stable {
170-
hir_id,
171-
attr_index,
172-
lint_index: Some(lint_index),
173-
attr_id: _,
174-
} => (*hir_id, *attr_index, *lint_index),
151+
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
152+
(*hir_id, *attr_index, *lint_index)
153+
}
175154
_ => {
176155
unreachable!("HashStable should only be called for a filled `LintExpectationId`")
177156
}

0 commit comments

Comments
 (0)