diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 5437ca65935f8..b5ae6ed4cda2f 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -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 { + // 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::>(); 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) diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 51fbcb8ebb805..7db556ff48580 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -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>, + pub single_imports: FxIndexSet>, /// The least shadowable known binding for this name, or None if there are no known bindings. pub binding: Option>, pub shadowed_glob: Option>, @@ -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); }); } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index f4a85c358e38c..c1916a3beba61 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -44,8 +44,6 @@ mod diagnostics; type Res = def::Res; -type IdentMap = FxHashMap; - 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, + pub bindings: FxIndexMap, pub kind: RibKind<'ra>, } @@ -1536,7 +1534,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. @@ -1564,7 +1562,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)); } } } @@ -2246,6 +2244,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 { @@ -3854,7 +3854,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } } - fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut IdentMap { + fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap { &mut self.ribs[ns].last_mut().unwrap().bindings } @@ -5008,7 +5008,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, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 09f5a8e96d3de..65c22b3b3a0af 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1957,6 +1957,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 @@ -2195,6 +2197,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)) diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 9abb3180388b3..017e0b37b8fa5 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -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)] diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 0b4d0e04c295c..d1e6a489580ee 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -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::>(); unused_arms.sort_by_key(|&(&arm_i, _)| arm_i);