Skip to content

Commit d65eab5

Browse files
committed
Auto merge of rust-lang#131213 - ismailarilik:handle-potential-query-instability-lint-for-rustc-resolve, r=<try>
Handle `rustc_resolve` cases of `rustc::potential_query_instability` lint This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_resolve/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/lib.rs#L12) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors. A somewhat tracking issue: rust-lang#84447 r? `@compiler-errors`
2 parents 8aca4ba + fb9cc98 commit d65eab5

File tree

7 files changed

+28
-29
lines changed

7 files changed

+28
-29
lines changed

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub struct ResolverGlobalCtxt {
175175
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
176176
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
177177
pub effective_visibilities: EffectiveVisibilities,
178-
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
178+
pub extern_crate_map: FxIndexMap<LocalDefId, CrateNum>,
179179
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
180180
pub module_children: LocalDefIdMap<Vec<ModChild>>,
181181
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,

compiler/rustc_resolve/src/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::{
55
self as ast, CRATE_NODE_ID, Crate, ItemKind, MetaItemInner, MetaItemKind, ModKind, NodeId, Path,
66
};
77
use rustc_ast_pretty::pprust;
8-
use rustc_data_structures::fx::FxHashSet;
8+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
99
use rustc_errors::codes::*;
1010
use rustc_errors::{
1111
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, MultiSpan, SuggestionStyle,
@@ -2842,7 +2842,7 @@ fn show_candidates(
28422842
let mut kinds = accessible_path_strings
28432843
.iter()
28442844
.map(|(_, descr, _, _, _)| *descr)
2845-
.collect::<FxHashSet<&str>>()
2845+
.collect::<FxIndexSet<&str>>()
28462846
.into_iter();
28472847
let kind = if let Some(kind) = kinds.next()
28482848
&& let None = kinds.next()

compiler/rustc_resolve/src/imports.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::cell::Cell;
44
use std::mem;
55

66
use rustc_ast::NodeId;
7-
use rustc_data_structures::fx::FxHashSet;
7+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
88
use rustc_data_structures::intern::Interned;
99
use rustc_errors::codes::*;
1010
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
@@ -220,7 +220,7 @@ impl<'ra> ImportData<'ra> {
220220
pub(crate) struct NameResolution<'ra> {
221221
/// Single imports that may define the name in the namespace.
222222
/// Imports are arena-allocated, so it's ok to use pointers as keys.
223-
pub single_imports: FxHashSet<Import<'ra>>,
223+
pub single_imports: FxIndexSet<Import<'ra>>,
224224
/// The least shadowable known binding for this name, or None if there are no known bindings.
225225
pub binding: Option<NameBinding<'ra>>,
226226
pub shadowed_glob: Option<NameBinding<'ra>>,
@@ -482,7 +482,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
482482
let key = BindingKey::new(target, ns);
483483
let _ = this.try_define(import.parent_scope.module, key, dummy_binding, false);
484484
this.update_resolution(import.parent_scope.module, key, false, |_, resolution| {
485-
resolution.single_imports.remove(&import);
485+
resolution.single_imports.shift_remove(&import);
486486
})
487487
});
488488
self.record_use(target, dummy_binding, Used::Other);
@@ -837,7 +837,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
837837
}
838838
let key = BindingKey::new(target, ns);
839839
this.update_resolution(parent, key, false, |_, resolution| {
840-
resolution.single_imports.remove(&import);
840+
resolution.single_imports.shift_remove(&import);
841841
});
842842
}
843843
}

compiler/rustc_resolve/src/late.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::mem::{replace, swap, take};
1515
use rustc_ast::ptr::P;
1616
use rustc_ast::visit::{AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, visit_opt, walk_list};
1717
use rustc_ast::*;
18-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
18+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
1919
use rustc_errors::codes::*;
2020
use rustc_errors::{Applicability, DiagArgValue, IntoDiagArg, StashKey, Suggestions};
2121
use rustc_hir::def::Namespace::{self, *};
@@ -44,7 +44,7 @@ mod diagnostics;
4444

4545
type Res = def::Res<NodeId>;
4646

47-
type IdentMap<T> = FxHashMap<Ident, T>;
47+
type IdentMap<T> = FxIndexMap<Ident, T>;
4848

4949
use diagnostics::{ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime};
5050

@@ -640,7 +640,7 @@ struct DiagMetadata<'ast> {
640640

641641
/// A list of labels as of yet unused. Labels will be removed from this map when
642642
/// they are used (in a `break` or `continue` statement)
643-
unused_labels: FxHashMap<NodeId, Span>,
643+
unused_labels: FxIndexMap<NodeId, Span>,
644644

645645
/// Only used for better errors on `let x = { foo: bar };`.
646646
/// In the case of a parse error with `let x = { foo: bar, };`, this isn't needed, it's only
@@ -1550,7 +1550,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15501550
// Allow all following defaults to refer to this type parameter.
15511551
forward_ty_ban_rib
15521552
.bindings
1553-
.remove(&Ident::with_dummy_span(param.ident.name));
1553+
.shift_remove(&Ident::with_dummy_span(param.ident.name));
15541554
}
15551555
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
15561556
// Const parameters can't have param bounds.
@@ -1578,7 +1578,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15781578
// Allow all following defaults to refer to this const parameter.
15791579
forward_const_ban_rib
15801580
.bindings
1581-
.remove(&Ident::with_dummy_span(param.ident.name));
1581+
.shift_remove(&Ident::with_dummy_span(param.ident.name));
15821582
}
15831583
}
15841584
}
@@ -2236,7 +2236,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
22362236
let local_candidates = self.lifetime_elision_candidates.take();
22372237

22382238
if let Some(candidates) = local_candidates {
2239-
let distinct: FxHashSet<_> = candidates.iter().map(|(res, _)| *res).collect();
2239+
let distinct: FxIndexSet<_> = candidates.iter().map(|(res, _)| *res).collect();
22402240
let lifetime_count = distinct.len();
22412241
if lifetime_count != 0 {
22422242
parameter_info.push(ElisionFnParameter {
@@ -4621,7 +4621,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46214621
Ok((node_id, _)) => {
46224622
// Since this res is a label, it is never read.
46234623
self.r.label_res_map.insert(expr.id, node_id);
4624-
self.diag_metadata.unused_labels.remove(&node_id);
4624+
self.diag_metadata.unused_labels.shift_remove(&node_id);
46254625
}
46264626
Err(error) => {
46274627
self.report_error(label.ident.span, error);

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
960960
Applicability::MaybeIncorrect,
961961
);
962962
// Do not lint against unused label when we suggest them.
963-
self.diag_metadata.unused_labels.remove(node_id);
963+
self.diag_metadata.unused_labels.shift_remove(node_id);
964964
}
965965
}
966966
}

compiler/rustc_resolve/src/lib.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// tidy-alphabetical-start
1010
#![allow(internal_features)]
1111
#![allow(rustc::diagnostic_outside_of_impl)]
12-
#![allow(rustc::potential_query_instability)]
1312
#![allow(rustc::untranslatable_diagnostic)]
1413
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1514
#![doc(rust_logo)]
@@ -1022,7 +1021,7 @@ pub struct Resolver<'ra, 'tcx> {
10221021
graph_root: Module<'ra>,
10231022

10241023
prelude: Option<Module<'ra>>,
1025-
extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'ra>>,
1024+
extern_prelude: FxIndexMap<Ident, ExternPreludeEntry<'ra>>,
10261025

10271026
/// N.B., this is used only for better diagnostics, not name resolution itself.
10281027
field_names: LocalDefIdMap<Vec<Ident>>,
@@ -1055,7 +1054,7 @@ pub struct Resolver<'ra, 'tcx> {
10551054
extra_lifetime_params_map: NodeMap<Vec<(Ident, NodeId, LifetimeRes)>>,
10561055

10571056
/// `CrateNum` resolutions of `extern crate` items.
1058-
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
1057+
extern_crate_map: FxIndexMap<LocalDefId, CrateNum>,
10591058
module_children: LocalDefIdMap<Vec<ModChild>>,
10601059
trait_map: NodeMap<Vec<TraitCandidate>>,
10611060

@@ -1078,7 +1077,7 @@ pub struct Resolver<'ra, 'tcx> {
10781077
/// some AST passes can generate identifiers that only resolve to local or
10791078
/// lang items.
10801079
empty_module: Module<'ra>,
1081-
module_map: FxHashMap<DefId, Module<'ra>>,
1080+
module_map: FxIndexMap<DefId, Module<'ra>>,
10821081
binding_parent_modules: FxHashMap<NameBinding<'ra>, Module<'ra>>,
10831082

10841083
underscore_disambiguator: u32,
@@ -1114,16 +1113,16 @@ pub struct Resolver<'ra, 'tcx> {
11141113
macro_names: FxHashSet<Ident>,
11151114
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
11161115
registered_tools: &'tcx RegisteredTools,
1117-
macro_use_prelude: FxHashMap<Symbol, NameBinding<'ra>>,
1116+
macro_use_prelude: FxIndexMap<Symbol, NameBinding<'ra>>,
11181117
macro_map: FxHashMap<DefId, MacroData>,
11191118
dummy_ext_bang: Lrc<SyntaxExtension>,
11201119
dummy_ext_derive: Lrc<SyntaxExtension>,
11211120
non_macro_attr: MacroData,
11221121
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'ra>>,
11231122
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'ra>>,
1124-
unused_macros: FxHashMap<LocalDefId, (NodeId, Ident)>,
1123+
unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
11251124
/// A map from the macro to all its potentially unused arms.
1126-
unused_macro_rules: FxIndexMap<LocalDefId, FxHashMap<usize, (Ident, Span)>>,
1125+
unused_macro_rules: FxIndexMap<LocalDefId, FxIndexMap<usize, (Ident, Span)>>,
11271126
proc_macro_stubs: FxHashSet<LocalDefId>,
11281127
/// Traces collected during macro resolution and validated when it's complete.
11291128
single_segment_macro_resolutions:
@@ -1235,7 +1234,7 @@ impl<'ra> ResolverArenas<'ra> {
12351234
expn_id: ExpnId,
12361235
span: Span,
12371236
no_implicit_prelude: bool,
1238-
module_map: &mut FxHashMap<DefId, Module<'ra>>,
1237+
module_map: &mut FxIndexMap<DefId, Module<'ra>>,
12391238
module_self_bindings: &mut FxHashMap<Module<'ra>, NameBinding<'ra>>,
12401239
) -> Module<'ra> {
12411240
let module = Module(Interned::new_unchecked(self.modules.alloc(ModuleData::new(
@@ -1380,7 +1379,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13801379
arenas: &'ra ResolverArenas<'ra>,
13811380
) -> Resolver<'ra, 'tcx> {
13821381
let root_def_id = CRATE_DEF_ID.to_def_id();
1383-
let mut module_map = FxHashMap::default();
1382+
let mut module_map = FxIndexMap::default();
13841383
let mut module_self_bindings = FxHashMap::default();
13851384
let graph_root = arenas.new_module(
13861385
None,
@@ -1397,7 +1396,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13971396
ExpnId::root(),
13981397
DUMMY_SP,
13991398
true,
1400-
&mut FxHashMap::default(),
1399+
&mut FxIndexMap::default(),
14011400
&mut FxHashMap::default(),
14021401
);
14031402

@@ -1413,7 +1412,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14131412
let mut invocation_parents = FxHashMap::default();
14141413
invocation_parents.insert(LocalExpnId::ROOT, InvocationParent::ROOT);
14151414

1416-
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = tcx
1415+
let mut extern_prelude: FxIndexMap<Ident, ExternPreludeEntry<'_>> = tcx
14171416
.sess
14181417
.opts
14191418
.externs
@@ -1513,7 +1512,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15131512
macro_names: FxHashSet::default(),
15141513
builtin_macros: Default::default(),
15151514
registered_tools,
1516-
macro_use_prelude: FxHashMap::default(),
1515+
macro_use_prelude: FxIndexMap::default(),
15171516
macro_map: FxHashMap::default(),
15181517
dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(edition)),
15191518
dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(edition)),

compiler/rustc_resolve/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
341341
fn record_macro_rule_usage(&mut self, id: NodeId, rule_i: usize) {
342342
let did = self.local_def_id(id);
343343
if let Some(rules) = self.unused_macro_rules.get_mut(&did) {
344-
rules.remove(&rule_i);
344+
rules.shift_remove(&rule_i);
345345
}
346346
}
347347

@@ -602,7 +602,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
602602
match res {
603603
Res::Def(DefKind::Macro(_), def_id) => {
604604
if let Some(def_id) = def_id.as_local() {
605-
self.unused_macros.remove(&def_id);
605+
self.unused_macros.shift_remove(&def_id);
606606
if self.proc_macro_stubs.contains(&def_id) {
607607
self.dcx().emit_err(errors::ProcMacroSameCrate {
608608
span: path.span,

0 commit comments

Comments
 (0)