rustc_lint: Make LintLevelsProvider::current_specs()
return &FxIndexMap
So that lint iteration order becomes predicitable. Discovered with `rustc::potential_query_instability`.
This commit is contained in:
parent
fcfe05aa75
commit
231dbbcb6a
4 changed files with 23 additions and 23 deletions
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Level, MultiSpan,
|
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Level, MultiSpan,
|
||||||
SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
|
SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
|
||||||
};
|
};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||||
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
|
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
|
||||||
use rustc_error_messages::FluentValue;
|
use rustc_error_messages::FluentValue;
|
||||||
use rustc_lint_defs::{Applicability, LintExpectationId};
|
use rustc_lint_defs::{Applicability, LintExpectationId};
|
||||||
|
@ -259,7 +259,7 @@ impl Diagnostic {
|
||||||
|
|
||||||
pub(crate) fn update_unstable_expectation_id(
|
pub(crate) fn update_unstable_expectation_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
|
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
|
||||||
) {
|
) {
|
||||||
if let Level::Expect(expectation_id) | Level::Warning(Some(expectation_id)) =
|
if let Level::Expect(expectation_id) | Level::Warning(Some(expectation_id)) =
|
||||||
&mut self.level
|
&mut self.level
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub use termcolor::{Color, ColorSpec, WriteColor};
|
||||||
use crate::diagnostic_impls::{DelayedAtWithNewline, DelayedAtWithoutNewline};
|
use crate::diagnostic_impls::{DelayedAtWithNewline, DelayedAtWithoutNewline};
|
||||||
use emitter::{is_case_difference, DynEmitter, Emitter, EmitterWriter};
|
use emitter::{is_case_difference, DynEmitter, Emitter, EmitterWriter};
|
||||||
use registry::Registry;
|
use registry::Registry;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
|
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
|
||||||
use rustc_data_structures::sync::{Lock, Lrc};
|
use rustc_data_structures::sync::{Lock, Lrc};
|
||||||
use rustc_data_structures::AtomicRef;
|
use rustc_data_structures::AtomicRef;
|
||||||
|
@ -1318,7 +1318,7 @@ impl DiagCtxt {
|
||||||
|
|
||||||
pub fn update_unstable_expectation_id(
|
pub fn update_unstable_expectation_id(
|
||||||
&self,
|
&self,
|
||||||
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
|
unstable_to_stable: &FxIndexMap<LintExpectationId, 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);
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
|
||||||
use rustc_feature::{Features, GateIssue};
|
use rustc_feature::{Features, GateIssue};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -73,7 +73,7 @@ rustc_index::newtype_index! {
|
||||||
struct LintSet {
|
struct LintSet {
|
||||||
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
|
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
|
||||||
// flag.
|
// flag.
|
||||||
specs: FxHashMap<LintId, LevelAndSource>,
|
specs: FxIndexMap<LintId, LevelAndSource>,
|
||||||
parent: LintStackIndex,
|
parent: LintStackIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ impl LintLevelSets {
|
||||||
&self,
|
&self,
|
||||||
lint: &'static Lint,
|
lint: &'static Lint,
|
||||||
idx: LintStackIndex,
|
idx: LintStackIndex,
|
||||||
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
|
aux: Option<&FxIndexMap<LintId, LevelAndSource>>,
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
) -> LevelAndSource {
|
) -> LevelAndSource {
|
||||||
let lint = LintId::of(lint);
|
let lint = LintId::of(lint);
|
||||||
|
@ -101,7 +101,7 @@ impl LintLevelSets {
|
||||||
&self,
|
&self,
|
||||||
id: LintId,
|
id: LintId,
|
||||||
mut idx: LintStackIndex,
|
mut idx: LintStackIndex,
|
||||||
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
|
aux: Option<&FxIndexMap<LintId, LevelAndSource>>,
|
||||||
) -> (Option<Level>, LintLevelSource) {
|
) -> (Option<Level>, LintLevelSource) {
|
||||||
if let Some(specs) = aux {
|
if let Some(specs) = aux {
|
||||||
if let Some(&(level, src)) = specs.get(&id) {
|
if let Some(&(level, src)) = specs.get(&id) {
|
||||||
|
@ -132,8 +132,8 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
|
||||||
cur: hir::CRATE_HIR_ID,
|
cur: hir::CRATE_HIR_ID,
|
||||||
specs: ShallowLintLevelMap::default(),
|
specs: ShallowLintLevelMap::default(),
|
||||||
expectations: Vec::new(),
|
expectations: Vec::new(),
|
||||||
unstable_to_stable_ids: FxHashMap::default(),
|
unstable_to_stable_ids: FxIndexMap::default(),
|
||||||
empty: FxHashMap::default(),
|
empty: FxIndexMap::default(),
|
||||||
},
|
},
|
||||||
lint_added_lints: false,
|
lint_added_lints: false,
|
||||||
store,
|
store,
|
||||||
|
@ -161,7 +161,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
|
||||||
tcx,
|
tcx,
|
||||||
cur: owner.into(),
|
cur: owner.into(),
|
||||||
specs: ShallowLintLevelMap::default(),
|
specs: ShallowLintLevelMap::default(),
|
||||||
empty: FxHashMap::default(),
|
empty: FxIndexMap::default(),
|
||||||
attrs,
|
attrs,
|
||||||
},
|
},
|
||||||
lint_added_lints: false,
|
lint_added_lints: false,
|
||||||
|
@ -209,14 +209,14 @@ pub struct TopDown {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LintLevelsProvider {
|
pub trait LintLevelsProvider {
|
||||||
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource>;
|
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource>;
|
||||||
fn insert(&mut self, id: LintId, lvl: LevelAndSource);
|
fn insert(&mut self, id: LintId, lvl: LevelAndSource);
|
||||||
fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource;
|
fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource;
|
||||||
fn push_expectation(&mut self, _id: LintExpectationId, _expectation: LintExpectation) {}
|
fn push_expectation(&mut self, _id: LintExpectationId, _expectation: LintExpectation) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintLevelsProvider for TopDown {
|
impl LintLevelsProvider for TopDown {
|
||||||
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
|
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
|
||||||
&self.sets.list[self.cur].specs
|
&self.sets.list[self.cur].specs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,12 +234,12 @@ struct LintLevelQueryMap<'tcx> {
|
||||||
cur: HirId,
|
cur: HirId,
|
||||||
specs: ShallowLintLevelMap,
|
specs: ShallowLintLevelMap,
|
||||||
/// Empty hash map to simplify code.
|
/// Empty hash map to simplify code.
|
||||||
empty: FxHashMap<LintId, LevelAndSource>,
|
empty: FxIndexMap<LintId, LevelAndSource>,
|
||||||
attrs: &'tcx hir::AttributeMap<'tcx>,
|
attrs: &'tcx hir::AttributeMap<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintLevelsProvider for LintLevelQueryMap<'_> {
|
impl LintLevelsProvider for LintLevelQueryMap<'_> {
|
||||||
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
|
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
|
||||||
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
|
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
|
||||||
}
|
}
|
||||||
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
|
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
|
||||||
|
@ -257,13 +257,13 @@ 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: FxHashMap<LintExpectationId, LintExpectationId>,
|
unstable_to_stable_ids: FxIndexMap<LintExpectationId, LintExpectationId>,
|
||||||
/// Empty hash map to simplify code.
|
/// Empty hash map to simplify code.
|
||||||
empty: FxHashMap<LintId, LevelAndSource>,
|
empty: FxIndexMap<LintId, LevelAndSource>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
|
impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
|
||||||
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
|
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
|
||||||
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
|
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
|
||||||
}
|
}
|
||||||
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
|
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
|
||||||
|
@ -486,7 +486,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
|
||||||
.provider
|
.provider
|
||||||
.sets
|
.sets
|
||||||
.list
|
.list
|
||||||
.push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE });
|
.push(LintSet { specs: FxIndexMap::default(), parent: COMMAND_LINE });
|
||||||
self.add_command_line();
|
self.add_command_line();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
|
||||||
) -> BuilderPush {
|
) -> BuilderPush {
|
||||||
let prev = self.provider.cur;
|
let prev = self.provider.cur;
|
||||||
self.provider.cur =
|
self.provider.cur =
|
||||||
self.provider.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev });
|
self.provider.sets.list.push(LintSet { specs: FxIndexMap::default(), parent: prev });
|
||||||
|
|
||||||
self.add(attrs, is_crate_node, source_hir_id);
|
self.add(attrs, is_crate_node, source_hir_id);
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||||
self.features
|
self.features
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
|
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
|
||||||
self.provider.current_specs()
|
self.provider.current_specs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_data_structures::sorted_map::SortedMap;
|
use rustc_data_structures::sorted_map::SortedMap;
|
||||||
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan};
|
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan};
|
||||||
use rustc_hir::{HirId, ItemLocalId};
|
use rustc_hir::{HirId, ItemLocalId};
|
||||||
|
@ -61,7 +61,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
|
||||||
/// by the attributes for *a single HirId*.
|
/// by the attributes for *a single HirId*.
|
||||||
#[derive(Default, Debug, HashStable)]
|
#[derive(Default, Debug, HashStable)]
|
||||||
pub struct ShallowLintLevelMap {
|
pub struct ShallowLintLevelMap {
|
||||||
pub specs: SortedMap<ItemLocalId, FxHashMap<LintId, LevelAndSource>>,
|
pub specs: SortedMap<ItemLocalId, FxIndexMap<LintId, LevelAndSource>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// From an initial level and source, verify the effect of special annotations:
|
/// From an initial level and source, verify the effect of special annotations:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue