Skip to content

Commit 2203ba2

Browse files
committed
Handle rustc_middle cases of rustc::potential_query_instability lint
1 parent 1e008dd commit 2203ba2

File tree

16 files changed

+55
-63
lines changed

16 files changed

+55
-63
lines changed

compiler/rustc_data_structures/src/sharded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub trait IntoPointer {
246246
fn into_pointer(&self) -> *const ();
247247
}
248248

249-
impl<K: Eq + Hash + Copy + IntoPointer> ShardedHashMap<K, ()> {
249+
impl<K: Eq + Hash + Copy + IntoPointer> ShardedIndexMap<K, ()> {
250250
pub fn contains_pointer_to<T: Hash + IntoPointer>(&self, value: &T) -> bool {
251251
let hash = make_hash(&value);
252252
let shard = self.lock_shard_by_hash(hash);

compiler/rustc_middle/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
// tidy-alphabetical-start
2828
#![allow(internal_features)]
2929
#![allow(rustc::diagnostic_outside_of_impl)]
30-
#![allow(rustc::potential_query_instability)]
3130
#![allow(rustc::untranslatable_diagnostic)]
3231
#![cfg_attr(doc, recursion_limit = "256")] // FIXME(nnethercote): will be removed by #124141
3332
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ rustc_queries! {
21692169
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
21702170
desc { "fetching potentially unused trait imports" }
21712171
}
2172-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
2172+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxIndexSet<Symbol> {
21732173
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
21742174
}
21752175

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::hash_map::Entry;
22
use std::mem;
33
use std::sync::Arc;
44

5-
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
5+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
66
use rustc_data_structures::memmap::Mmap;
77
use rustc_data_structures::sync::{HashMapExt, Lock, RwLock};
88
use rustc_data_structures::unhash::UnhashMap;
@@ -57,7 +57,7 @@ pub struct OnDiskCache {
5757

5858
// Collects all `QuerySideEffect` created during the current compilation
5959
// session.
60-
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffect>>,
60+
current_side_effects: Lock<FxIndexMap<DepNodeIndex, QuerySideEffect>>,
6161

6262
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,
6363

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ use rustc_data_structures::fingerprint::Fingerprint;
2222
use rustc_data_structures::fx::FxHashMap;
2323
use rustc_data_structures::intern::Interned;
2424
use rustc_data_structures::profiling::SelfProfilerRef;
25-
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
25+
use rustc_data_structures::sharded::{IntoPointer, ShardedIndexMap};
2626
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2727
use rustc_data_structures::steal::Steal;
2828
use rustc_data_structures::sync::{
2929
self, DynSend, DynSync, FreezeReadGuard, Lock, RwLock, WorkerLocal,
3030
};
31-
use rustc_data_structures::unord::UnordSet;
3231
use rustc_errors::{
3332
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, LintDiagnostic, MultiSpan,
3433
};
@@ -788,7 +787,7 @@ impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
788787
}
789788
}
790789

791-
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
790+
type InternedSet<'tcx, T> = ShardedIndexMap<InternedInSet<'tcx, T>, ()>;
792791

793792
pub struct CtxtInterners<'tcx> {
794793
/// The arena that types, regions, etc. are allocated from.
@@ -3355,9 +3354,7 @@ pub fn provide(providers: &mut Providers) {
33553354
providers.maybe_unused_trait_imports =
33563355
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
33573356
providers.names_imported_by_glob_use = |tcx, id| {
3358-
tcx.arena.alloc(UnordSet::from(
3359-
tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(),
3360-
))
3357+
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
33613358
};
33623359

33633360
providers.extern_mod_stmt_cnum =

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fmt::Write;
44
use std::ops::ControlFlow;
55

6-
use rustc_data_structures::fx::FxHashMap;
6+
use rustc_data_structures::fx::FxIndexMap;
77
use rustc_errors::{
88
Applicability, Diag, DiagArgValue, IntoDiagArg, into_diag_arg_using_display, listify, pluralize,
99
};
@@ -287,7 +287,7 @@ pub fn suggest_constraining_type_params<'a>(
287287
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
288288
span_to_replace: Option<Span>,
289289
) -> bool {
290-
let mut grouped = FxHashMap::default();
290+
let mut grouped = FxIndexMap::default();
291291
let mut unstable_suggestion = false;
292292
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
293293
let stable = match def_id {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub struct ResolverGlobalCtxt {
172172
pub extern_crate_map: UnordMap<LocalDefId, CrateNum>,
173173
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
174174
pub module_children: LocalDefIdMap<Vec<ModChild>>,
175-
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
175+
pub glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
176176
pub main_def: Option<MainDefinition>,
177177
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
178178
/// A list of proc macro LocalDefIds, written out in the order in which

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::ops::{Deref, DerefMut};
66
use rustc_abi::{ExternAbi, Size};
77
use rustc_apfloat::Float;
88
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
9-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
9+
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
1010
use rustc_data_structures::unord::UnordMap;
1111
use rustc_hir as hir;
1212
use rustc_hir::LangItem;
@@ -3489,8 +3489,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
34893489

34903490
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
34913491
// non-unique pairs will have a `None` entry.
3492-
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
3493-
&mut FxHashMap::default();
3492+
let unique_symbols_rev: &mut FxIndexMap<(Namespace, Symbol), Option<DefId>> =
3493+
&mut FxIndexMap::default();
34943494

34953495
for symbol_set in tcx.resolutions(()).glob_map.values() {
34963496
for symbol in symbol_set {
@@ -3500,27 +3500,23 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
35003500
}
35013501
}
35023502

3503-
for_each_def(tcx, |ident, ns, def_id| {
3504-
use std::collections::hash_map::Entry::{Occupied, Vacant};
3505-
3506-
match unique_symbols_rev.entry((ns, ident.name)) {
3507-
Occupied(mut v) => match v.get() {
3508-
None => {}
3509-
Some(existing) => {
3510-
if *existing != def_id {
3511-
v.insert(None);
3512-
}
3503+
for_each_def(tcx, |ident, ns, def_id| match unique_symbols_rev.entry((ns, ident.name)) {
3504+
IndexEntry::Occupied(mut v) => match v.get() {
3505+
None => {}
3506+
Some(existing) => {
3507+
if *existing != def_id {
3508+
v.insert(None);
35133509
}
3514-
},
3515-
Vacant(v) => {
3516-
v.insert(Some(def_id));
35173510
}
3511+
},
3512+
IndexEntry::Vacant(v) => {
3513+
v.insert(Some(def_id));
35183514
}
35193515
});
35203516

35213517
// Put the symbol from all the unique namespace+symbol pairs into `map`.
35223518
let mut map: DefIdMap<Symbol> = Default::default();
3523-
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain() {
3519+
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain(..) {
35243520
use std::collections::hash_map::Entry::{Occupied, Vacant};
35253521

35263522
if let Some(def_id) = opt_def_id {

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ pub struct Resolver<'ra, 'tcx> {
11041104
underscore_disambiguator: u32,
11051105

11061106
/// Maps glob imports to the names of items actually imported.
1107-
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
1107+
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
11081108
glob_error: Option<ErrorGuaranteed>,
11091109
visibilities_for_hashing: Vec<(LocalDefId, ty::Visibility)>,
11101110
used_imports: FxHashSet<NodeId>,

src/tools/clippy/clippy_lints/src/wildcard_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl LateLintPass<'_> for WildcardImports {
150150
(span, false)
151151
};
152152

153-
let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord();
153+
let mut imports: Vec<_> = used_imports.iter().map(ToString::to_string).collect();
154154
let imports_string = if imports.len() == 1 {
155155
imports.pop().unwrap()
156156
} else if braced_glob {

0 commit comments

Comments
 (0)