Use AttrId key for unstable<->stable expectation map.
This commit is contained in:
parent
9649706ead
commit
4928b22fa8
3 changed files with 16 additions and 22 deletions
|
@ -12,7 +12,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId};
|
||||||
use rustc_macros::{Decodable, Encodable};
|
use rustc_macros::{Decodable, Encodable};
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{AttrId, Span, DUMMY_SP};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::snippet::Style;
|
use crate::snippet::Style;
|
||||||
|
@ -356,24 +356,19 @@ impl DiagInner {
|
||||||
|
|
||||||
pub(crate) fn update_unstable_expectation_id(
|
pub(crate) fn update_unstable_expectation_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
|
unstable_to_stable: &FxIndexMap<AttrId, LintExpectationId>,
|
||||||
) {
|
) {
|
||||||
if let Level::Expect(expectation_id) | Level::ForceWarning(Some(expectation_id)) =
|
if let Level::Expect(expectation_id) | Level::ForceWarning(Some(expectation_id)) =
|
||||||
&mut self.level
|
&mut self.level
|
||||||
|
&& let LintExpectationId::Unstable { attr_id, lint_index } = *expectation_id
|
||||||
{
|
{
|
||||||
if expectation_id.is_stable() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index.
|
// The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index.
|
||||||
// The lint index inside the attribute is manually transferred here.
|
// The lint index inside the attribute is manually transferred here.
|
||||||
let lint_index = expectation_id.get_lint_index();
|
let Some(stable_id) = unstable_to_stable.get(&attr_id) else {
|
||||||
expectation_id.set_lint_index(None);
|
panic!("{expectation_id:?} must have a matching stable id")
|
||||||
let mut stable_id = unstable_to_stable
|
};
|
||||||
.get(expectation_id)
|
|
||||||
.expect("each unstable `LintExpectationId` must have a matching stable id")
|
|
||||||
.normalize();
|
|
||||||
|
|
||||||
|
let mut stable_id = stable_id.normalize();
|
||||||
stable_id.set_lint_index(lint_index);
|
stable_id.set_lint_index(lint_index);
|
||||||
*expectation_id = stable_id;
|
*expectation_id = stable_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ use rustc_macros::{Decodable, Encodable};
|
||||||
pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
|
pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
pub use rustc_span::ErrorGuaranteed;
|
pub use rustc_span::ErrorGuaranteed;
|
||||||
use rustc_span::{Loc, Span, DUMMY_SP};
|
use rustc_span::{AttrId, Loc, Span, DUMMY_SP};
|
||||||
pub use snippet::Style;
|
pub use snippet::Style;
|
||||||
// Used by external projects such as `rust-gpu`.
|
// Used by external projects such as `rust-gpu`.
|
||||||
// See https://github.com/rust-lang/rust/pull/115393.
|
// See https://github.com/rust-lang/rust/pull/115393.
|
||||||
|
@ -1096,7 +1096,7 @@ impl<'a> DiagCtxtHandle<'a> {
|
||||||
|
|
||||||
pub fn update_unstable_expectation_id(
|
pub fn update_unstable_expectation_id(
|
||||||
&self,
|
&self,
|
||||||
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
|
unstable_to_stable: FxIndexMap<AttrId, LintExpectationId>,
|
||||||
) {
|
) {
|
||||||
let mut inner = self.inner.borrow_mut();
|
let mut inner = self.inner.borrow_mut();
|
||||||
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);
|
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);
|
||||||
|
@ -1105,7 +1105,7 @@ impl<'a> DiagCtxtHandle<'a> {
|
||||||
if !diags.is_empty() {
|
if !diags.is_empty() {
|
||||||
inner.suppressed_expected_diag = true;
|
inner.suppressed_expected_diag = true;
|
||||||
for mut diag in diags.into_iter() {
|
for mut diag in diags.into_iter() {
|
||||||
diag.update_unstable_expectation_id(unstable_to_stable);
|
diag.update_unstable_expectation_id(&unstable_to_stable);
|
||||||
|
|
||||||
// Here the diagnostic is given back to `emit_diagnostic` where it was first
|
// Here the diagnostic is given back to `emit_diagnostic` where it was first
|
||||||
// intercepted. Now it should be processed as usual, since the unstable expectation
|
// intercepted. Now it should be processed as usual, since the unstable expectation
|
||||||
|
@ -1117,11 +1117,11 @@ impl<'a> DiagCtxtHandle<'a> {
|
||||||
inner
|
inner
|
||||||
.stashed_diagnostics
|
.stashed_diagnostics
|
||||||
.values_mut()
|
.values_mut()
|
||||||
.for_each(|(diag, _guar)| diag.update_unstable_expectation_id(unstable_to_stable));
|
.for_each(|(diag, _guar)| diag.update_unstable_expectation_id(&unstable_to_stable));
|
||||||
inner
|
inner
|
||||||
.future_breakage_diagnostics
|
.future_breakage_diagnostics
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.for_each(|diag| diag.update_unstable_expectation_id(unstable_to_stable));
|
.for_each(|diag| diag.update_unstable_expectation_id(&unstable_to_stable));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This methods steals all [`LintExpectationId`]s that are stored inside
|
/// This methods steals all [`LintExpectationId`]s that are stored inside
|
||||||
|
|
|
@ -20,7 +20,7 @@ use rustc_session::lint::builtin::{
|
||||||
use rustc_session::lint::{Level, Lint, LintExpectationId, LintId};
|
use rustc_session::lint::{Level, Lint, LintExpectationId, LintId};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{AttrId, Span, DUMMY_SP};
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
use {rustc_ast as ast, rustc_hir as hir};
|
use {rustc_ast as ast, rustc_hir as hir};
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
|
||||||
builder.add_id(hir::CRATE_HIR_ID);
|
builder.add_id(hir::CRATE_HIR_ID);
|
||||||
tcx.hir().walk_toplevel_module(&mut builder);
|
tcx.hir().walk_toplevel_module(&mut builder);
|
||||||
|
|
||||||
tcx.dcx().update_unstable_expectation_id(&builder.provider.unstable_to_stable_ids);
|
tcx.dcx().update_unstable_expectation_id(builder.provider.unstable_to_stable_ids);
|
||||||
|
|
||||||
builder.provider.expectations
|
builder.provider.expectations
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ struct QueryMapExpectationsWrapper<'tcx> {
|
||||||
/// Level map for `cur`.
|
/// Level map for `cur`.
|
||||||
specs: ShallowLintLevelMap,
|
specs: ShallowLintLevelMap,
|
||||||
expectations: Vec<(LintExpectationId, LintExpectation)>,
|
expectations: Vec<(LintExpectationId, LintExpectation)>,
|
||||||
unstable_to_stable_ids: FxIndexMap<LintExpectationId, LintExpectationId>,
|
unstable_to_stable_ids: FxIndexMap<AttrId, LintExpectationId>,
|
||||||
/// Empty hash map to simplify code.
|
/// Empty hash map to simplify code.
|
||||||
empty: FxIndexMap<LintId, LevelAndSource>,
|
empty: FxIndexMap<LintId, LevelAndSource>,
|
||||||
}
|
}
|
||||||
|
@ -274,9 +274,8 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
|
||||||
else {
|
else {
|
||||||
bug!("unstable expectation id should already be mapped")
|
bug!("unstable expectation id should already be mapped")
|
||||||
};
|
};
|
||||||
let key = LintExpectationId::Unstable { attr_id, lint_index: None };
|
|
||||||
|
|
||||||
self.unstable_to_stable_ids.entry(key).or_insert(LintExpectationId::Stable {
|
self.unstable_to_stable_ids.entry(attr_id).or_insert(LintExpectationId::Stable {
|
||||||
hir_id,
|
hir_id,
|
||||||
attr_index,
|
attr_index,
|
||||||
lint_index: None,
|
lint_index: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue