Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle rustc_resolve cases of rustc::potential_query_instability lint #131213

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1086,6 +1086,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
this.add_module_candidates(module, &mut suggestions, filter_fn, None);
}
Scope::MacroUsePrelude => {
// The suggestions are deterministically sorted at the bottom of this function.
#[allow(rustc::potential_query_instability)]
suggestions.extend(this.macro_use_prelude.iter().filter_map(
|(name, binding)| {
let res = binding.res();
@@ -1104,6 +1106,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
}
Scope::ExternPrelude => {
// The suggestions are deterministically sorted at the bottom of this function.
#[allow(rustc::potential_query_instability)]
suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| {
let res = Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id());
filter_fn(res).then_some(TypoSuggestion::typo_from_ident(*ident, res))
@@ -1362,7 +1366,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
);

if lookup_ident.span.at_least_rust_2018() {
for ident in self.extern_prelude.clone().into_keys() {
// `idents` is sorted before usage so ordering is not important here.
#[allow(rustc::potential_query_instability)]
let mut idents: Vec<_> = self.extern_prelude.clone().into_keys().collect();
idents.sort_by_key(|ident| ident.span);

for ident in idents {
if ident.span.from_expansion() {
// Idents are adjusted to the root context before being
// resolved in the extern prelude, so reporting this to the
@@ -1467,7 +1476,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
return;
}

let unused_macro = self.unused_macros.iter().find_map(|(def_id, (_, unused_ident))| {
// Make ordering consistent before iteration
#[allow(rustc::potential_query_instability)]
let mut unused_macros: Vec<_> = self.unused_macros.iter().collect();
unused_macros.sort_by_key(|&(_, (key, _))| key);
let unused_macro = unused_macros.iter().find_map(|(def_id, (_, unused_ident))| {
if unused_ident.name == ident.name { Some((def_id, unused_ident)) } else { None }
});

@@ -1954,6 +1967,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ident: Symbol,
current_module: Module<'ra>,
) -> Option<Symbol> {
// The candidates are sorted just below.
#[allow(rustc::potential_query_instability)]
let mut candidates = self
.extern_prelude
.keys()
@@ -2342,6 +2357,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// Sort extern crate names in *reverse* order to get
// 1) some consistent ordering for emitted diagnostics, and
// 2) `std` suggestions before `core` suggestions.
#[allow(rustc::potential_query_instability)]
let mut extern_crate_names =
self.extern_prelude.keys().map(|ident| ident.name).collect::<Vec<_>>();
extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap());
@@ -2839,6 +2855,8 @@ fn show_candidates(
} else {
// Get the unique item kinds and if there's only one, we use the right kind name
// instead of the more generic "items".
// Ordering is not important if there's only one element in the set.
#[allow(rustc::potential_query_instability)]
let mut kinds = accessible_path_strings
.iter()
.map(|(_, descr, _, _, _)| *descr)
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
@@ -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};
@@ -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>>,
@@ -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.swap_remove(&import);
})
});
self.record_use(target, dummy_binding, Used::Other);
@@ -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.swap_remove(&import);
});
}
}
19 changes: 12 additions & 7 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
@@ -44,8 +44,6 @@ mod diagnostics;

type Res = def::Res<NodeId>;

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

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

#[derive(Copy, Clone, Debug)]
@@ -261,7 +259,7 @@ impl RibKind<'_> {
/// resolving, the name is looked up from inside out.
#[derive(Debug)]
pub(crate) struct Rib<'ra, R = Res> {
pub bindings: IdentMap<R>,
pub bindings: FxIndexMap<Ident, R>,
pub kind: RibKind<'ra>,
}

@@ -1550,7 +1548,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));
.swap_remove(&Ident::with_dummy_span(param.ident.name));
}
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
// Const parameters can't have param bounds.
@@ -1578,7 +1576,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));
.swap_remove(&Ident::with_dummy_span(param.ident.name));
}
}
}
@@ -2260,6 +2258,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
}));
}
// Ordering is not important if there's only one element in the set.
#[allow(rustc::potential_query_instability)]
let mut distinct_iter = distinct.into_iter();
if let Some(res) = distinct_iter.next() {
match elision_lifetime {
@@ -3868,7 +3868,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
}

fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut IdentMap<Res> {
fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap<Ident, Res> {
&mut self.ribs[ns].last_mut().unwrap().bindings
}

@@ -5046,7 +5046,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let mut late_resolution_visitor = LateResolutionVisitor::new(self);
late_resolution_visitor.resolve_doc_links(&krate.attrs, MaybeExported::Ok(CRATE_NODE_ID));
visit::walk_crate(&mut late_resolution_visitor, krate);
for (id, span) in late_resolution_visitor.diag_metadata.unused_labels.iter() {
// Make ordering consistent before iteration
#[allow(rustc::potential_query_instability)]
let mut unused_labels: Vec<_> =
late_resolution_visitor.diag_metadata.unused_labels.iter().collect();
unused_labels.sort_by_key(|&(key, _)| key);
for (id, span) in unused_labels {
self.lint_buffer.buffer_lint(
lint::builtin::UNUSED_LABELS,
*id,
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1928,6 +1928,8 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
let Some(default_trait) = default_trait else {
return;
};
// The ordering is not important because `any` is used on the iterator.
#[allow(rustc::potential_query_instability)]
if self
.r
.extern_crate_map
@@ -2166,6 +2168,8 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
// Items from the prelude
if !module.no_implicit_prelude {
let extern_prelude = self.r.extern_prelude.clone();
// The names are sorted at the bottom of this function.
#[allow(rustc::potential_query_instability)]
names.extend(extern_prelude.iter().flat_map(|(ident, _)| {
self.r
.crate_loader(|c| c.maybe_process_path_extern(ident.name))
1 change: 0 additions & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
8 changes: 7 additions & 1 deletion compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
@@ -346,7 +346,11 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
}

fn check_unused_macros(&mut self) {
for (_, &(node_id, ident)) in self.unused_macros.iter() {
// Make ordering consistent before iteration
#[allow(rustc::potential_query_instability)]
let mut unused_macros: Vec<_> = self.unused_macros.iter().collect();
unused_macros.sort_by_key(|&(_, (key, _))| key);
for (_, &(node_id, ident)) in unused_macros {
self.lint_buffer.buffer_lint(
UNUSED_MACROS,
node_id,
@@ -356,6 +360,8 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
}

for (&def_id, unused_arms) in self.unused_macro_rules.iter() {
// It is already sorted below.
#[allow(rustc::potential_query_instability)]
let mut unused_arms = unused_arms.iter().collect::<Vec<_>>();
unused_arms.sort_by_key(|&(&arm_i, _)| arm_i);

Loading