Skip to content

Commit 59c132e

Browse files
committed
Remove attr_id from stable lint ids.
1 parent 8a1da1a commit 59c132e

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
@@ -367,7 +367,7 @@ impl DiagInner {
367367
panic!("{expectation_id:?} must have a matching stable id")
368368
};
369369

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

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ impl DiagCtxtInner {
15561556
if let LintExpectationId::Unstable { .. } = expect_id {
15571557
unreachable!(); // this case was handled at the top of this function
15581558
}
1559-
self.fulfilled_expectations.insert(expect_id.normalize());
1559+
self.fulfilled_expectations.insert(expect_id);
15601560
if let Expect(_) = diagnostic.level {
15611561
// Nothing emitted here for expected lints.
15621562
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);

compiler/rustc_lint/src/expect.rs

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

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

compiler/rustc_lint/src/levels.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
226226
self.specs.lint_level_id_at_node(self.tcx, LintId::of(lint), self.cur)
227227
}
228228
fn push_expectation(&mut self, id: LintExpectationId, expectation: LintExpectation) {
229-
self.specs.expectations.push((id.normalize(), expectation))
229+
self.specs.expectations.push((id, expectation))
230230
}
231231
}
232232

@@ -494,13 +494,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
494494
/// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
495495
/// (e.g. if a forbid was already inserted on the same scope), then emits a
496496
/// diagnostic with no change to `specs`.
497-
fn insert_spec(&mut self, id: LintId, (mut level, src): LevelAndSource) {
497+
fn insert_spec(&mut self, id: LintId, (level, src): LevelAndSource) {
498498
let (old_level, old_src) = self.provider.get_lint_level(id.lint, self.sess);
499-
if let Level::Expect(id) = &mut level
500-
&& let LintExpectationId::Stable { .. } = id
501-
{
502-
*id = id.normalize();
503-
}
499+
504500
// Setting to a non-forbid level is an error if the lint previously had
505501
// a forbid level. Note that this is not necessarily true even with a
506502
// `#[forbid(..)]` attribute present, as that is overridden by `--cap-lints`.
@@ -613,17 +609,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
613609
// This is the only lint level with a `LintExpectationId` that can be created from
614610
// an attribute.
615611
Some(Level::Expect(unstable_id)) if let Some(hir_id) = source_hir_id => {
616-
let LintExpectationId::Unstable { attr_id, lint_index } = unstable_id else {
612+
let LintExpectationId::Unstable { lint_index: None, attr_id: _ } = unstable_id
613+
else {
617614
bug!("stable id Level::from_attr")
618615
};
619616

620617
let stable_id = LintExpectationId::Stable {
621618
hir_id,
622619
attr_index: attr_index.try_into().unwrap(),
623-
lint_index,
624-
// We pass the previous unstable attr_id such that we can trace the ast id
625-
// when building a map to go from unstable to stable id.
626-
attr_id: Some(attr_id),
620+
lint_index: None,
627621
};
628622

629623
Level::Expect(stable_id)

compiler/rustc_lint_defs/src/lib.rs

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

101101
impl LintExpectationId {
@@ -119,31 +119,13 @@ impl LintExpectationId {
119119

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

137124
impl<HCX: rustc_hir::HashStableContext> HashStable<HCX> for LintExpectationId {
138125
#[inline]
139126
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
140127
match self {
141-
LintExpectationId::Stable {
142-
hir_id,
143-
attr_index,
144-
lint_index: Some(lint_index),
145-
attr_id: _,
146-
} => {
128+
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
147129
hir_id.hash_stable(hcx, hasher);
148130
attr_index.hash_stable(hcx, hasher);
149131
lint_index.hash_stable(hcx, hasher);
@@ -163,12 +145,9 @@ impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectation
163145
#[inline]
164146
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
165147
match self {
166-
LintExpectationId::Stable {
167-
hir_id,
168-
attr_index,
169-
lint_index: Some(lint_index),
170-
attr_id: _,
171-
} => (*hir_id, *attr_index, *lint_index),
148+
LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
149+
(*hir_id, *attr_index, *lint_index)
150+
}
172151
_ => {
173152
unreachable!("HashStable should only be called for a filled `LintExpectationId`")
174153
}

0 commit comments

Comments
 (0)