Skip to content

Commit da9a8fd

Browse files
committed
Handle rustc_middle cases of rustc::potential_query_instability lint
1 parent 360f7d7 commit da9a8fd

File tree

12 files changed

+42
-37
lines changed

12 files changed

+42
-37
lines changed

Cargo.lock

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is automatically @generated by Cargo.
22
# It is not intended for manual editing.
3-
version = 3
3+
version = 4
44

55
[[package]]
66
name = "addr2line"
@@ -1495,6 +1495,12 @@ dependencies = [
14951495
"serde",
14961496
]
14971497

1498+
[[package]]
1499+
name = "hashbrown"
1500+
version = "0.15.0"
1501+
source = "registry+https://github.com/rust-lang/crates.io-index"
1502+
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
1503+
14981504
[[package]]
14991505
name = "heck"
15001506
version = "0.4.1"
@@ -1743,12 +1749,12 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
17431749

17441750
[[package]]
17451751
name = "indexmap"
1746-
version = "2.5.0"
1752+
version = "2.6.0"
17471753
source = "registry+https://github.com/rust-lang/crates.io-index"
1748-
checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
1754+
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
17491755
dependencies = [
17501756
"equivalent",
1751-
"hashbrown",
1757+
"hashbrown 0.15.0",
17521758
"rustc-rayon",
17531759
"serde",
17541760
]
@@ -2442,7 +2448,7 @@ checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a"
24422448
dependencies = [
24432449
"crc32fast",
24442450
"flate2",
2445-
"hashbrown",
2451+
"hashbrown 0.14.5",
24462452
"indexmap",
24472453
"memchr",
24482454
"ruzstd",
@@ -2471,7 +2477,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
24712477
checksum = "30c7f82d6d446dd295845094f3a76bcdc5e6183b66667334e169f019cd05e5a0"
24722478
dependencies = [
24732479
"ahash",
2474-
"hashbrown",
2480+
"hashbrown 0.14.5",
24752481
"parking_lot",
24762482
"stable_deref_trait",
24772483
]
@@ -3999,6 +4005,7 @@ dependencies = [
39994005
"either",
40004006
"field-offset",
40014007
"gsgdt",
4008+
"indexmap",
40024009
"polonius-engine",
40034010
"rustc-rayon-core",
40044011
"rustc_apfloat",
@@ -5186,7 +5193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
51865193
checksum = "813ba76597db32dc4f6992fd8bf8f394715b88d352fd97401da67dab6283b4c6"
51875194
dependencies = [
51885195
"gimli 0.30.0",
5189-
"hashbrown",
5196+
"hashbrown 0.14.5",
51905197
"object 0.36.4",
51915198
"tracing",
51925199
]
@@ -5846,7 +5853,7 @@ checksum = "b09e46c7fceceaa72b2dd1a8a137ea7fd8f93dfaa69806010a709918e496c5dc"
58465853
dependencies = [
58475854
"ahash",
58485855
"bitflags 2.6.0",
5849-
"hashbrown",
5856+
"hashbrown 0.14.5",
58505857
"indexmap",
58515858
"semver",
58525859
"serde",

compiler/rustc_data_structures/src/sharded.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::borrow::Borrow;
2-
use std::collections::hash_map::RawEntryMut;
32
use std::hash::{Hash, Hasher};
43
use std::{iter, mem};
54

65
#[cfg(parallel_compiler)]
76
use either::Either;
7+
use indexmap::map::RawEntryApiV1;
8+
use indexmap::map::raw_entry_v1::RawEntryMut;
89

9-
use crate::fx::{FxHashMap, FxHasher};
10+
use crate::fx::{FxHasher, FxIndexMap};
1011
#[cfg(parallel_compiler)]
1112
use crate::sync::{CacheAligned, is_dyn_thread_safe};
1213
use crate::sync::{Lock, LockGuard, Mode};
@@ -159,15 +160,15 @@ pub fn shards() -> usize {
159160
1
160161
}
161162

162-
pub type ShardedHashMap<K, V> = Sharded<FxHashMap<K, V>>;
163+
pub type ShardedIndexMap<K, V> = Sharded<FxIndexMap<K, V>>;
163164

164-
impl<K: Eq, V> ShardedHashMap<K, V> {
165+
impl<K: Eq, V> ShardedIndexMap<K, V> {
165166
pub fn len(&self) -> usize {
166167
self.lock_shards().map(|shard| shard.len()).sum()
167168
}
168169
}
169170

170-
impl<K: Eq + Hash + Copy> ShardedHashMap<K, ()> {
171+
impl<K: Eq + Hash + Copy> ShardedIndexMap<K, ()> {
171172
#[inline]
172173
pub fn intern_ref<Q: ?Sized>(&self, value: &Q, make: impl FnOnce() -> K) -> K
173174
where
@@ -176,7 +177,7 @@ impl<K: Eq + Hash + Copy> ShardedHashMap<K, ()> {
176177
{
177178
let hash = make_hash(value);
178179
let mut shard = self.lock_shard_by_hash(hash);
179-
let entry = shard.raw_entry_mut().from_key_hashed_nocheck(hash, value);
180+
let entry = shard.raw_entry_mut_v1().from_key_hashed_nocheck(hash, value);
180181

181182
match entry {
182183
RawEntryMut::Occupied(e) => *e.key(),
@@ -196,7 +197,7 @@ impl<K: Eq + Hash + Copy> ShardedHashMap<K, ()> {
196197
{
197198
let hash = make_hash(&value);
198199
let mut shard = self.lock_shard_by_hash(hash);
199-
let entry = shard.raw_entry_mut().from_key_hashed_nocheck(hash, &value);
200+
let entry = shard.raw_entry_mut_v1().from_key_hashed_nocheck(hash, &value);
200201

201202
match entry {
202203
RawEntryMut::Occupied(e) => *e.key(),
@@ -214,12 +215,12 @@ pub trait IntoPointer {
214215
fn into_pointer(&self) -> *const ();
215216
}
216217

217-
impl<K: Eq + Hash + Copy + IntoPointer> ShardedHashMap<K, ()> {
218+
impl<K: Eq + Hash + Copy + IntoPointer> ShardedIndexMap<K, ()> {
218219
pub fn contains_pointer_to<T: Hash + IntoPointer>(&self, value: &T) -> bool {
219220
let hash = make_hash(&value);
220221
let shard = self.lock_shard_by_hash(hash);
221222
let value = value.into_pointer();
222-
shard.raw_entry().from_hash(hash, |entry| entry.into_pointer() == value).is_some()
223+
shard.raw_entry_v1().from_hash(hash, |entry| entry.into_pointer() == value).is_some()
223224
}
224225
}
225226

compiler/rustc_middle/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ derive-where = "1.2.7"
1010
either = "1.5.0"
1111
field-offset = "0.3.5"
1212
gsgdt = "0.1.2"
13+
indexmap = "2.6.0"
1314
polonius-engine = "0.13.0"
1415
rustc-rayon-core = { version = "0.5.0", optional = true }
1516
rustc_apfloat = "0.2.0"

compiler/rustc_middle/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
// tidy-alphabetical-start
2727
#![allow(internal_features)]
2828
#![allow(rustc::diagnostic_outside_of_impl)]
29-
#![allow(rustc::potential_query_instability)]
3029
#![allow(rustc::untranslatable_diagnostic)]
3130
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3231
#![doc(rust_logo)]

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ rustc_queries! {
19201920
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
19211921
desc { "fetching potentially unused trait imports" }
19221922
}
1923-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
1923+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxIndexSet<Symbol> {
19241924
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
19251925
}
19261926

compiler/rustc_middle/src/query/on_disk_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::hash_map::Entry;
22
use std::mem;
33

4-
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
4+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
55
use rustc_data_structures::memmap::Mmap;
66
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, RwLock};
77
use rustc_data_structures::unhash::UnhashMap;
@@ -54,7 +54,7 @@ pub struct OnDiskCache<'sess> {
5454

5555
// Collects all `QuerySideEffects` created during the current compilation
5656
// session.
57-
current_side_effects: Lock<FxHashMap<DepNodeIndex, QuerySideEffects>>,
57+
current_side_effects: Lock<FxIndexMap<DepNodeIndex, QuerySideEffects>>,
5858

5959
source_map: &'sess SourceMap,
6060
file_index_to_stable_id: FxHashMap<SourceFileIndex, EncodedSourceFileId>,

compiler/rustc_middle/src/ty/context.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ use rustc_data_structures::fingerprint::Fingerprint;
1818
use rustc_data_structures::fx::FxHashMap;
1919
use rustc_data_structures::intern::Interned;
2020
use rustc_data_structures::profiling::SelfProfilerRef;
21-
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
21+
use rustc_data_structures::sharded::{IntoPointer, ShardedIndexMap};
2222
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2323
use rustc_data_structures::steal::Steal;
2424
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, RwLock, WorkerLocal};
2525
#[cfg(parallel_compiler)]
2626
use rustc_data_structures::sync::{DynSend, DynSync};
27-
use rustc_data_structures::unord::UnordSet;
2827
use rustc_errors::{
2928
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, LintDiagnostic, MultiSpan,
3029
};
@@ -698,7 +697,7 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
698697
}
699698
}
700699

701-
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
700+
type InternedSet<'tcx, T> = ShardedIndexMap<InternedInSet<'tcx, T>, ()>;
702701

703702
pub struct CtxtInterners<'tcx> {
704703
/// The arena that types, regions, etc. are allocated from.
@@ -3207,9 +3206,7 @@ pub fn provide(providers: &mut Providers) {
32073206
providers.maybe_unused_trait_imports =
32083207
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
32093208
providers.names_imported_by_glob_use = |tcx, id| {
3210-
tcx.arena.alloc(UnordSet::from(
3211-
tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(),
3212-
))
3209+
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
32133210
};
32143211

32153212
providers.extern_mod_stmt_cnum =

compiler/rustc_middle/src/ty/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::borrow::Cow;
44
use std::fmt::Write;
55
use std::ops::ControlFlow;
66

7-
use rustc_data_structures::fx::FxHashMap;
7+
use rustc_data_structures::fx::FxIndexMap;
88
use rustc_errors::{Applicability, Diag, DiagArgValue, IntoDiagArg, into_diag_arg_using_display};
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::DefId;
@@ -276,7 +276,7 @@ pub fn suggest_constraining_type_params<'a>(
276276
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
277277
span_to_replace: Option<Span>,
278278
) -> bool {
279-
let mut grouped = FxHashMap::default();
279+
let mut grouped = FxIndexMap::default();
280280
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
281281
grouped.entry(param_name).or_insert(Vec::new()).push((constraint, def_id))
282282
});

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub struct ResolverGlobalCtxt {
178178
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
179179
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
180180
pub module_children: LocalDefIdMap<Vec<ModChild>>,
181-
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
181+
pub glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
182182
pub main_def: Option<MainDefinition>,
183183
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
184184
/// A list of proc macro LocalDefIds, written out in the order in which

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut};
55

66
use rustc_apfloat::Float;
77
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
8-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
8+
use rustc_data_structures::fx::FxIndexMap;
99
use rustc_data_structures::unord::UnordMap;
1010
use rustc_hir as hir;
1111
use rustc_hir::LangItem;
@@ -3316,8 +3316,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33163316

33173317
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
33183318
// non-unique pairs will have a `None` entry.
3319-
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
3320-
&mut FxHashMap::default();
3319+
let unique_symbols_rev: &mut FxIndexMap<(Namespace, Symbol), Option<DefId>> =
3320+
&mut FxIndexMap::default();
33213321

33223322
for symbol_set in tcx.resolutions(()).glob_map.values() {
33233323
for symbol in symbol_set {
@@ -3328,7 +3328,7 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33283328
}
33293329

33303330
for_each_def(tcx, |ident, ns, def_id| {
3331-
use std::collections::hash_map::Entry::{Occupied, Vacant};
3331+
use indexmap::map::Entry::{Occupied, Vacant};
33323332

33333333
match unique_symbols_rev.entry((ns, ident.name)) {
33343334
Occupied(mut v) => match v.get() {
@@ -3347,7 +3347,7 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33473347

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

33533353
if let Some(def_id) = opt_def_id {

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ pub struct Resolver<'ra, 'tcx> {
10861086
empty_disambiguator: u32,
10871087

10881088
/// Maps glob imports to the names of items actually imported.
1089-
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
1089+
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
10901090
glob_error: Option<ErrorGuaranteed>,
10911091
visibilities_for_hashing: Vec<(LocalDefId, ty::Visibility)>,
10921092
used_imports: FxHashSet<NodeId>,

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

+1-1
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)