Skip to content

Commit

Permalink
Auto merge of rust-lang#131213 - ismailarilik:handle-potential-query-…
Browse files Browse the repository at this point in the history
…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`
  • Loading branch information
bors committed Oct 24, 2024
2 parents 8aca4ba + fb9cc98 commit d65eab5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub struct ResolverGlobalCtxt {
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
pub effective_visibilities: EffectiveVisibilities,
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
pub extern_crate_map: FxIndexMap<LocalDefId, CrateNum>,
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
pub module_children: LocalDefIdMap<Vec<ModChild>>,
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_ast::{
self as ast, CRATE_NODE_ID, Crate, ItemKind, MetaItemInner, MetaItemKind, ModKind, NodeId, Path,
};
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, MultiSpan, SuggestionStyle,
Expand Down Expand Up @@ -2842,7 +2842,7 @@ fn show_candidates(
let mut kinds = accessible_path_strings
.iter()
.map(|(_, descr, _, _, _)| *descr)
.collect::<FxHashSet<&str>>()
.collect::<FxIndexSet<&str>>()
.into_iter();
let kind = if let Some(kind) = kinds.next()
&& let None = kinds.next()
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::cell::Cell;
use std::mem;

use rustc_ast::NodeId;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_data_structures::intern::Interned;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'ra> ImportData<'ra> {
pub(crate) struct NameResolution<'ra> {
/// Single imports that may define the name in the namespace.
/// Imports are arena-allocated, so it's ok to use pointers as keys.
pub single_imports: FxHashSet<Import<'ra>>,
pub single_imports: FxIndexSet<Import<'ra>>,
/// The least shadowable known binding for this name, or None if there are no known bindings.
pub binding: Option<NameBinding<'ra>>,
pub shadowed_glob: Option<NameBinding<'ra>>,
Expand Down Expand Up @@ -482,7 +482,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let key = BindingKey::new(target, ns);
let _ = this.try_define(import.parent_scope.module, key, dummy_binding, false);
this.update_resolution(import.parent_scope.module, key, false, |_, resolution| {
resolution.single_imports.remove(&import);
resolution.single_imports.shift_remove(&import);
})
});
self.record_use(target, dummy_binding, Used::Other);
Expand Down Expand Up @@ -837,7 +837,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
let key = BindingKey::new(target, ns);
this.update_resolution(parent, key, false, |_, resolution| {
resolution.single_imports.remove(&import);
resolution.single_imports.shift_remove(&import);
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::mem::{replace, swap, take};
use rustc_ast::ptr::P;
use rustc_ast::visit::{AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, visit_opt, walk_list};
use rustc_ast::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::codes::*;
use rustc_errors::{Applicability, DiagArgValue, IntoDiagArg, StashKey, Suggestions};
use rustc_hir::def::Namespace::{self, *};
Expand Down Expand Up @@ -44,7 +44,7 @@ mod diagnostics;

type Res = def::Res<NodeId>;

type IdentMap<T> = FxHashMap<Ident, T>;
type IdentMap<T> = FxIndexMap<Ident, T>;

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

Expand Down Expand Up @@ -640,7 +640,7 @@ struct DiagMetadata<'ast> {

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

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

if let Some(candidates) = local_candidates {
let distinct: FxHashSet<_> = candidates.iter().map(|(res, _)| *res).collect();
let distinct: FxIndexSet<_> = candidates.iter().map(|(res, _)| *res).collect();
let lifetime_count = distinct.len();
if lifetime_count != 0 {
parameter_info.push(ElisionFnParameter {
Expand Down Expand Up @@ -4621,7 +4621,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
Ok((node_id, _)) => {
// Since this res is a label, it is never read.
self.r.label_res_map.insert(expr.id, node_id);
self.diag_metadata.unused_labels.remove(&node_id);
self.diag_metadata.unused_labels.shift_remove(&node_id);
}
Err(error) => {
self.report_error(label.ident.span, error);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
Applicability::MaybeIncorrect,
);
// Do not lint against unused label when we suggest them.
self.diag_metadata.unused_labels.remove(node_id);
self.diag_metadata.unused_labels.shift_remove(node_id);
}
}
}
Expand Down
23 changes: 11 additions & 12 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::potential_query_instability)]
#![allow(rustc::untranslatable_diagnostic)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
Expand Down Expand Up @@ -1022,7 +1021,7 @@ pub struct Resolver<'ra, 'tcx> {
graph_root: Module<'ra>,

prelude: Option<Module<'ra>>,
extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'ra>>,
extern_prelude: FxIndexMap<Ident, ExternPreludeEntry<'ra>>,

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

/// `CrateNum` resolutions of `extern crate` items.
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
extern_crate_map: FxIndexMap<LocalDefId, CrateNum>,
module_children: LocalDefIdMap<Vec<ModChild>>,
trait_map: NodeMap<Vec<TraitCandidate>>,

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

underscore_disambiguator: u32,
Expand Down Expand Up @@ -1114,16 +1113,16 @@ pub struct Resolver<'ra, 'tcx> {
macro_names: FxHashSet<Ident>,
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
registered_tools: &'tcx RegisteredTools,
macro_use_prelude: FxHashMap<Symbol, NameBinding<'ra>>,
macro_use_prelude: FxIndexMap<Symbol, NameBinding<'ra>>,
macro_map: FxHashMap<DefId, MacroData>,
dummy_ext_bang: Lrc<SyntaxExtension>,
dummy_ext_derive: Lrc<SyntaxExtension>,
non_macro_attr: MacroData,
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'ra>>,
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'ra>>,
unused_macros: FxHashMap<LocalDefId, (NodeId, Ident)>,
unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
/// A map from the macro to all its potentially unused arms.
unused_macro_rules: FxIndexMap<LocalDefId, FxHashMap<usize, (Ident, Span)>>,
unused_macro_rules: FxIndexMap<LocalDefId, FxIndexMap<usize, (Ident, Span)>>,
proc_macro_stubs: FxHashSet<LocalDefId>,
/// Traces collected during macro resolution and validated when it's complete.
single_segment_macro_resolutions:
Expand Down Expand Up @@ -1235,7 +1234,7 @@ impl<'ra> ResolverArenas<'ra> {
expn_id: ExpnId,
span: Span,
no_implicit_prelude: bool,
module_map: &mut FxHashMap<DefId, Module<'ra>>,
module_map: &mut FxIndexMap<DefId, Module<'ra>>,
module_self_bindings: &mut FxHashMap<Module<'ra>, NameBinding<'ra>>,
) -> Module<'ra> {
let module = Module(Interned::new_unchecked(self.modules.alloc(ModuleData::new(
Expand Down Expand Up @@ -1380,7 +1379,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
arenas: &'ra ResolverArenas<'ra>,
) -> Resolver<'ra, 'tcx> {
let root_def_id = CRATE_DEF_ID.to_def_id();
let mut module_map = FxHashMap::default();
let mut module_map = FxIndexMap::default();
let mut module_self_bindings = FxHashMap::default();
let graph_root = arenas.new_module(
None,
Expand All @@ -1397,7 +1396,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ExpnId::root(),
DUMMY_SP,
true,
&mut FxHashMap::default(),
&mut FxIndexMap::default(),
&mut FxHashMap::default(),
);

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

let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = tcx
let mut extern_prelude: FxIndexMap<Ident, ExternPreludeEntry<'_>> = tcx
.sess
.opts
.externs
Expand Down Expand Up @@ -1513,7 +1512,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
macro_names: FxHashSet::default(),
builtin_macros: Default::default(),
registered_tools,
macro_use_prelude: FxHashMap::default(),
macro_use_prelude: FxIndexMap::default(),
macro_map: FxHashMap::default(),
dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(edition)),
dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(edition)),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
fn record_macro_rule_usage(&mut self, id: NodeId, rule_i: usize) {
let did = self.local_def_id(id);
if let Some(rules) = self.unused_macro_rules.get_mut(&did) {
rules.remove(&rule_i);
rules.shift_remove(&rule_i);
}
}

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

0 comments on commit d65eab5

Please sign in to comment.