Skip to content

Commit e51e98d

Browse files
committed
Auto merge of #119251 - Enselic:rustc_lint-query-stability, r=cjgillot
rustc_lint: Enforce `rustc::potential_query_instability` lint Stop allowing `rustc::potential_query_instability` on all of `rustc_lint` and instead allow it on a case-by-case basis if it is safe to do so. In this particular crate, all lints were safe to allow. Part of #84447 which is E-help-wanted.
2 parents 67b6975 + 295d600 commit e51e98d

File tree

8 files changed

+36
-24
lines changed

8 files changed

+36
-24
lines changed

compiler/rustc_errors/src/diagnostic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Level, MultiSpan,
44
SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
55
};
6-
use rustc_data_structures::fx::FxHashMap;
6+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
77
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
88
use rustc_error_messages::FluentValue;
99
use rustc_lint_defs::{Applicability, LintExpectationId};
@@ -259,7 +259,7 @@ impl Diagnostic {
259259

260260
pub(crate) fn update_unstable_expectation_id(
261261
&mut self,
262-
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
262+
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
263263
) {
264264
if let Level::Expect(expectation_id) | Level::Warning(Some(expectation_id)) =
265265
&mut self.level

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub use termcolor::{Color, ColorSpec, WriteColor};
5555
use crate::diagnostic_impls::{DelayedAtWithNewline, DelayedAtWithoutNewline};
5656
use emitter::{is_case_difference, DynEmitter, Emitter, EmitterWriter};
5757
use registry::Registry;
58-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
58+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
5959
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
6060
use rustc_data_structures::sync::{Lock, Lrc};
6161
use rustc_data_structures::AtomicRef;
@@ -1318,7 +1318,7 @@ impl DiagCtxt {
13181318

13191319
pub fn update_unstable_expectation_id(
13201320
&self,
1321-
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
1321+
unstable_to_stable: &FxIndexMap<LintExpectationId, LintExpectationId>,
13221322
) {
13231323
let mut inner = self.inner.borrow_mut();
13241324
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);

compiler/rustc_lint/src/context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ impl LintStore {
430430
// Note: find_best_match_for_name depends on the sort order of its input vector.
431431
// To ensure deterministic output, sort elements of the lint_groups hash map.
432432
// Also, never suggest deprecated lint groups.
433+
// We will soon sort, so the initial order does not matter.
434+
#[allow(rustc::potential_query_instability)]
433435
let mut groups: Vec<_> = self
434436
.lint_groups
435437
.iter()

compiler/rustc_lint/src/context/diagnostics.rs

+5
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ pub(super) fn builtin(
197197
if let Some(ExpectedValues::Some(best_match_values)) =
198198
sess.parse_sess.check_config.expecteds.get(&best_match)
199199
{
200+
// We will soon sort, so the initial order does not matter.
201+
#[allow(rustc::potential_query_instability)]
200202
let mut possibilities =
201203
best_match_values.iter().flatten().map(Symbol::as_str).collect::<Vec<_>>();
202204
possibilities.sort();
@@ -298,6 +300,9 @@ pub(super) fn builtin(
298300
);
299301
};
300302
let mut have_none_possibility = false;
303+
// We later sort possibilities if it is not empty, so the
304+
// order here does not matter.
305+
#[allow(rustc::potential_query_instability)]
301306
let possibilities: Vec<Symbol> = values
302307
.iter()
303308
.inspect(|a| have_none_possibility |= a.is_none())

compiler/rustc_lint/src/levels.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
};
1616
use rustc_ast as ast;
1717
use rustc_ast_pretty::pprust;
18-
use rustc_data_structures::fx::FxHashMap;
18+
use rustc_data_structures::fx::FxIndexMap;
1919
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
2020
use rustc_feature::{Features, GateIssue};
2121
use rustc_hir as hir;
@@ -73,7 +73,7 @@ rustc_index::newtype_index! {
7373
struct LintSet {
7474
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
7575
// flag.
76-
specs: FxHashMap<LintId, LevelAndSource>,
76+
specs: FxIndexMap<LintId, LevelAndSource>,
7777
parent: LintStackIndex,
7878
}
7979

@@ -86,7 +86,7 @@ impl LintLevelSets {
8686
&self,
8787
lint: &'static Lint,
8888
idx: LintStackIndex,
89-
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
89+
aux: Option<&FxIndexMap<LintId, LevelAndSource>>,
9090
sess: &Session,
9191
) -> LevelAndSource {
9292
let lint = LintId::of(lint);
@@ -101,7 +101,7 @@ impl LintLevelSets {
101101
&self,
102102
id: LintId,
103103
mut idx: LintStackIndex,
104-
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
104+
aux: Option<&FxIndexMap<LintId, LevelAndSource>>,
105105
) -> (Option<Level>, LintLevelSource) {
106106
if let Some(specs) = aux {
107107
if let Some(&(level, src)) = specs.get(&id) {
@@ -132,8 +132,8 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
132132
cur: hir::CRATE_HIR_ID,
133133
specs: ShallowLintLevelMap::default(),
134134
expectations: Vec::new(),
135-
unstable_to_stable_ids: FxHashMap::default(),
136-
empty: FxHashMap::default(),
135+
unstable_to_stable_ids: FxIndexMap::default(),
136+
empty: FxIndexMap::default(),
137137
},
138138
lint_added_lints: false,
139139
store,
@@ -161,7 +161,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
161161
tcx,
162162
cur: owner.into(),
163163
specs: ShallowLintLevelMap::default(),
164-
empty: FxHashMap::default(),
164+
empty: FxIndexMap::default(),
165165
attrs,
166166
},
167167
lint_added_lints: false,
@@ -209,14 +209,14 @@ pub struct TopDown {
209209
}
210210

211211
pub trait LintLevelsProvider {
212-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource>;
212+
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource>;
213213
fn insert(&mut self, id: LintId, lvl: LevelAndSource);
214214
fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource;
215215
fn push_expectation(&mut self, _id: LintExpectationId, _expectation: LintExpectation) {}
216216
}
217217

218218
impl LintLevelsProvider for TopDown {
219-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
219+
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
220220
&self.sets.list[self.cur].specs
221221
}
222222

@@ -234,12 +234,12 @@ struct LintLevelQueryMap<'tcx> {
234234
cur: HirId,
235235
specs: ShallowLintLevelMap,
236236
/// Empty hash map to simplify code.
237-
empty: FxHashMap<LintId, LevelAndSource>,
237+
empty: FxIndexMap<LintId, LevelAndSource>,
238238
attrs: &'tcx hir::AttributeMap<'tcx>,
239239
}
240240

241241
impl LintLevelsProvider for LintLevelQueryMap<'_> {
242-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
242+
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
243243
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
244244
}
245245
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
@@ -257,13 +257,13 @@ struct QueryMapExpectationsWrapper<'tcx> {
257257
/// Level map for `cur`.
258258
specs: ShallowLintLevelMap,
259259
expectations: Vec<(LintExpectationId, LintExpectation)>,
260-
unstable_to_stable_ids: FxHashMap<LintExpectationId, LintExpectationId>,
260+
unstable_to_stable_ids: FxIndexMap<LintExpectationId, LintExpectationId>,
261261
/// Empty hash map to simplify code.
262-
empty: FxHashMap<LintId, LevelAndSource>,
262+
empty: FxIndexMap<LintId, LevelAndSource>,
263263
}
264264

265265
impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
266-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
266+
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
267267
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
268268
}
269269
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
@@ -486,7 +486,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
486486
.provider
487487
.sets
488488
.list
489-
.push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE });
489+
.push(LintSet { specs: FxIndexMap::default(), parent: COMMAND_LINE });
490490
self.add_command_line();
491491
}
492492

@@ -512,7 +512,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
512512
) -> BuilderPush {
513513
let prev = self.provider.cur;
514514
self.provider.cur =
515-
self.provider.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev });
515+
self.provider.sets.list.push(LintSet { specs: FxIndexMap::default(), parent: prev });
516516

517517
self.add(attrs, is_crate_node, source_hir_id);
518518

@@ -547,7 +547,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
547547
self.features
548548
}
549549

550-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
550+
fn current_specs(&self) -> &FxIndexMap<LintId, LevelAndSource> {
551551
self.provider.current_specs()
552552
}
553553

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
//!
2626
//! This API is completely unstable and subject to change.
2727
28-
#![allow(rustc::potential_query_instability)]
2928
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3029
#![doc(rust_logo)]
3130
#![feature(rustdoc_internals)]

compiler/rustc_lint/src/non_ascii_idents.rs

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ impl EarlyLintPass for NonAsciiIdents {
174174

175175
// Sort by `Span` so that error messages make sense with respect to the
176176
// order of identifier locations in the code.
177+
// We will soon sort, so the initial order does not matter.
178+
#[allow(rustc::potential_query_instability)]
177179
let mut symbols: Vec<_> = symbols.iter().collect();
178180
symbols.sort_by_key(|k| k.1);
179181

@@ -287,6 +289,8 @@ impl EarlyLintPass for NonAsciiIdents {
287289
}
288290

289291
if has_suspicious {
292+
// The end result is put in `lint_reports` which is sorted.
293+
#[allow(rustc::potential_query_instability)]
290294
let verified_augmented_script_sets = script_states
291295
.iter()
292296
.flat_map(|(k, v)| match v {
@@ -299,6 +303,8 @@ impl EarlyLintPass for NonAsciiIdents {
299303
let mut lint_reports: BTreeMap<(Span, Vec<char>), AugmentedScriptSet> =
300304
BTreeMap::new();
301305

306+
// The end result is put in `lint_reports` which is sorted.
307+
#[allow(rustc::potential_query_instability)]
302308
'outerloop: for (augment_script_set, usage) in script_states {
303309
let ScriptSetUsage::Suspicious(mut ch_list, sp) = usage else { continue };
304310

compiler/rustc_middle/src/lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cmp;
22

3-
use rustc_data_structures::fx::FxHashMap;
3+
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::sorted_map::SortedMap;
55
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan};
66
use rustc_hir::{HirId, ItemLocalId};
@@ -61,7 +61,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
6161
/// by the attributes for *a single HirId*.
6262
#[derive(Default, Debug, HashStable)]
6363
pub struct ShallowLintLevelMap {
64-
pub specs: SortedMap<ItemLocalId, FxHashMap<LintId, LevelAndSource>>,
64+
pub specs: SortedMap<ItemLocalId, FxIndexMap<LintId, LevelAndSource>>,
6565
}
6666

6767
/// From an initial level and source, verify the effect of special annotations:

0 commit comments

Comments
 (0)