Skip to content

Commit 4af4ec8

Browse files
committed
Use AttrId key for unstable<->stable expectation map.
1 parent f6fa358 commit 4af4ec8

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
1010
use rustc_macros::{Decodable, Encodable};
1111
use rustc_span::source_map::Spanned;
1212
use rustc_span::symbol::Symbol;
13-
use rustc_span::{Span, DUMMY_SP};
13+
use rustc_span::{AttrId, Span, DUMMY_SP};
1414
use std::borrow::Cow;
1515
use std::fmt::{self, Debug};
1616
use std::hash::{Hash, Hasher};
@@ -355,24 +355,19 @@ impl DiagInner {
355355

356356
pub(crate) fn update_unstable_expectation_id(
357357
&mut self,
358-
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
358+
unstable_to_stable: &FxIndexMap<AttrId, LintExpectationId>,
359359
) {
360360
if let Level::Expect(expectation_id) | Level::ForceWarning(Some(expectation_id)) =
361361
&mut self.level
362+
&& let LintExpectationId::Unstable { attr_id, lint_index } = *expectation_id
362363
{
363-
if expectation_id.is_stable() {
364-
return;
365-
}
366-
367364
// The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index.
368365
// The lint index inside the attribute is manually transferred here.
369-
let lint_index = expectation_id.get_lint_index();
370-
expectation_id.set_lint_index(None);
371-
let mut stable_id = unstable_to_stable
372-
.get(expectation_id)
373-
.expect("each unstable `LintExpectationId` must have a matching stable id")
374-
.normalize();
366+
let Some(stable_id) = unstable_to_stable.get(&attr_id) else {
367+
panic!("{expectation_id:?} must have a matching stable id")
368+
};
375369

370+
let mut stable_id = stable_id.normalize();
376371
stable_id.set_lint_index(lint_index);
377372
*expectation_id = stable_id;
378373
}

compiler/rustc_errors/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use rustc_data_structures::AtomicRef;
6060
use rustc_lint_defs::LintExpectationId;
6161
use rustc_macros::{Decodable, Encodable};
6262
use rustc_span::source_map::SourceMap;
63-
use rustc_span::{Loc, Span, DUMMY_SP};
63+
use rustc_span::{AttrId, Loc, Span, DUMMY_SP};
6464
use std::backtrace::{Backtrace, BacktraceStatus};
6565
use std::borrow::Cow;
6666
use std::cell::Cell;
@@ -1085,7 +1085,7 @@ impl<'a> DiagCtxtHandle<'a> {
10851085

10861086
pub fn update_unstable_expectation_id(
10871087
&self,
1088-
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
1088+
unstable_to_stable: FxIndexMap<AttrId, LintExpectationId>,
10891089
) {
10901090
let mut inner = self.inner.borrow_mut();
10911091
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);
@@ -1094,7 +1094,7 @@ impl<'a> DiagCtxtHandle<'a> {
10941094
if !diags.is_empty() {
10951095
inner.suppressed_expected_diag = true;
10961096
for mut diag in diags.into_iter() {
1097-
diag.update_unstable_expectation_id(unstable_to_stable);
1097+
diag.update_unstable_expectation_id(&unstable_to_stable);
10981098

10991099
// Here the diagnostic is given back to `emit_diagnostic` where it was first
11001100
// intercepted. Now it should be processed as usual, since the unstable expectation
@@ -1106,11 +1106,11 @@ impl<'a> DiagCtxtHandle<'a> {
11061106
inner
11071107
.stashed_diagnostics
11081108
.values_mut()
1109-
.for_each(|(diag, _guar)| diag.update_unstable_expectation_id(unstable_to_stable));
1109+
.for_each(|(diag, _guar)| diag.update_unstable_expectation_id(&unstable_to_stable));
11101110
inner
11111111
.future_breakage_diagnostics
11121112
.iter_mut()
1113-
.for_each(|diag| diag.update_unstable_expectation_id(unstable_to_stable));
1113+
.for_each(|diag| diag.update_unstable_expectation_id(&unstable_to_stable));
11141114
}
11151115

11161116
/// This methods steals all [`LintExpectationId`]s that are stored inside

compiler/rustc_lint/src/levels.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_session::lint::{
3939
};
4040
use rustc_session::Session;
4141
use rustc_span::symbol::{sym, Symbol};
42-
use rustc_span::{Span, DUMMY_SP};
42+
use rustc_span::{AttrId, Span, DUMMY_SP};
4343
use tracing::{debug, instrument};
4444

4545
use crate::errors::{
@@ -146,7 +146,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
146146
builder.add_id(hir::CRATE_HIR_ID);
147147
tcx.hir().walk_toplevel_module(&mut builder);
148148

149-
tcx.dcx().update_unstable_expectation_id(&builder.provider.unstable_to_stable_ids);
149+
tcx.dcx().update_unstable_expectation_id(builder.provider.unstable_to_stable_ids);
150150

151151
builder.provider.expectations
152152
}
@@ -260,7 +260,7 @@ struct QueryMapExpectationsWrapper<'tcx> {
260260
/// Level map for `cur`.
261261
specs: ShallowLintLevelMap,
262262
expectations: Vec<(LintExpectationId, LintExpectation)>,
263-
unstable_to_stable_ids: FxIndexMap<LintExpectationId, LintExpectationId>,
263+
unstable_to_stable_ids: FxIndexMap<AttrId, LintExpectationId>,
264264
/// Empty hash map to simplify code.
265265
empty: FxIndexMap<LintId, LevelAndSource>,
266266
}
@@ -282,9 +282,8 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
282282
else {
283283
bug!("unstable expectation id should already be mapped")
284284
};
285-
let key = LintExpectationId::Unstable { attr_id, lint_index: None };
286285

287-
self.unstable_to_stable_ids.entry(key).or_insert(LintExpectationId::Stable {
286+
self.unstable_to_stable_ids.entry(attr_id).or_insert(LintExpectationId::Stable {
288287
hir_id,
289288
attr_index,
290289
lint_index: None,

0 commit comments

Comments
 (0)