Skip to content

Commit 4928b22

Browse files
committed
Use AttrId key for unstable<->stable expectation map.
1 parent 9649706 commit 4928b22

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
@@ -12,7 +12,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
1212
use rustc_macros::{Decodable, Encodable};
1313
use rustc_span::source_map::Spanned;
1414
use rustc_span::symbol::Symbol;
15-
use rustc_span::{Span, DUMMY_SP};
15+
use rustc_span::{AttrId, Span, DUMMY_SP};
1616
use tracing::debug;
1717

1818
use crate::snippet::Style;
@@ -356,24 +356,19 @@ impl DiagInner {
356356

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

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

compiler/rustc_errors/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use rustc_macros::{Decodable, Encodable};
6969
pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
7070
use rustc_span::source_map::SourceMap;
7171
pub use rustc_span::ErrorGuaranteed;
72-
use rustc_span::{Loc, Span, DUMMY_SP};
72+
use rustc_span::{AttrId, Loc, Span, DUMMY_SP};
7373
pub use snippet::Style;
7474
// Used by external projects such as `rust-gpu`.
7575
// See https://github.com/rust-lang/rust/pull/115393.
@@ -1096,7 +1096,7 @@ impl<'a> DiagCtxtHandle<'a> {
10961096

10971097
pub fn update_unstable_expectation_id(
10981098
&self,
1099-
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
1099+
unstable_to_stable: FxIndexMap<AttrId, LintExpectationId>,
11001100
) {
11011101
let mut inner = self.inner.borrow_mut();
11021102
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);
@@ -1105,7 +1105,7 @@ impl<'a> DiagCtxtHandle<'a> {
11051105
if !diags.is_empty() {
11061106
inner.suppressed_expected_diag = true;
11071107
for mut diag in diags.into_iter() {
1108-
diag.update_unstable_expectation_id(unstable_to_stable);
1108+
diag.update_unstable_expectation_id(&unstable_to_stable);
11091109

11101110
// Here the diagnostic is given back to `emit_diagnostic` where it was first
11111111
// intercepted. Now it should be processed as usual, since the unstable expectation
@@ -1117,11 +1117,11 @@ impl<'a> DiagCtxtHandle<'a> {
11171117
inner
11181118
.stashed_diagnostics
11191119
.values_mut()
1120-
.for_each(|(diag, _guar)| diag.update_unstable_expectation_id(unstable_to_stable));
1120+
.for_each(|(diag, _guar)| diag.update_unstable_expectation_id(&unstable_to_stable));
11211121
inner
11221122
.future_breakage_diagnostics
11231123
.iter_mut()
1124-
.for_each(|diag| diag.update_unstable_expectation_id(unstable_to_stable));
1124+
.for_each(|diag| diag.update_unstable_expectation_id(&unstable_to_stable));
11251125
}
11261126

11271127
/// 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
@@ -20,7 +20,7 @@ use rustc_session::lint::builtin::{
2020
use rustc_session::lint::{Level, Lint, LintExpectationId, LintId};
2121
use rustc_session::Session;
2222
use rustc_span::symbol::{sym, Symbol};
23-
use rustc_span::{Span, DUMMY_SP};
23+
use rustc_span::{AttrId, Span, DUMMY_SP};
2424
use tracing::{debug, instrument};
2525
use {rustc_ast as ast, rustc_hir as hir};
2626

@@ -138,7 +138,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
138138
builder.add_id(hir::CRATE_HIR_ID);
139139
tcx.hir().walk_toplevel_module(&mut builder);
140140

141-
tcx.dcx().update_unstable_expectation_id(&builder.provider.unstable_to_stable_ids);
141+
tcx.dcx().update_unstable_expectation_id(builder.provider.unstable_to_stable_ids);
142142

143143
builder.provider.expectations
144144
}
@@ -252,7 +252,7 @@ struct QueryMapExpectationsWrapper<'tcx> {
252252
/// Level map for `cur`.
253253
specs: ShallowLintLevelMap,
254254
expectations: Vec<(LintExpectationId, LintExpectation)>,
255-
unstable_to_stable_ids: FxIndexMap<LintExpectationId, LintExpectationId>,
255+
unstable_to_stable_ids: FxIndexMap<AttrId, LintExpectationId>,
256256
/// Empty hash map to simplify code.
257257
empty: FxIndexMap<LintId, LevelAndSource>,
258258
}
@@ -274,9 +274,8 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
274274
else {
275275
bug!("unstable expectation id should already be mapped")
276276
};
277-
let key = LintExpectationId::Unstable { attr_id, lint_index: None };
278277

279-
self.unstable_to_stable_ids.entry(key).or_insert(LintExpectationId::Stable {
278+
self.unstable_to_stable_ids.entry(attr_id).or_insert(LintExpectationId::Stable {
280279
hir_id,
281280
attr_index,
282281
lint_index: None,

0 commit comments

Comments
 (0)