Skip to content

Commit afeabb2

Browse files
committed
Handle rustc_middle cases of rustc::potential_query_instability lint
1 parent ad9c494 commit afeabb2

18 files changed

+72
-67
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
]
@@ -4000,6 +4006,7 @@ dependencies = [
40004006
"either",
40014007
"field-offset",
40024008
"gsgdt",
4009+
"indexmap",
40034010
"polonius-engine",
40044011
"rustc-rayon-core",
40054012
"rustc_apfloat",
@@ -5187,7 +5194,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
51875194
checksum = "813ba76597db32dc4f6992fd8bf8f394715b88d352fd97401da67dab6283b4c6"
51885195
dependencies = [
51895196
"gimli 0.30.0",
5190-
"hashbrown",
5197+
"hashbrown 0.14.5",
51915198
"object 0.36.4",
51925199
"tracing",
51935200
]
@@ -5847,7 +5854,7 @@ checksum = "b09e46c7fceceaa72b2dd1a8a137ea7fd8f93dfaa69806010a709918e496c5dc"
58475854
dependencies = [
58485855
"ahash",
58495856
"bitflags 2.6.0",
5850-
"hashbrown",
5857+
"hashbrown 0.14.5",
58515858
"indexmap",
58525859
"semver",
58535860
"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;
@@ -3338,8 +3338,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33383338

33393339
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
33403340
// non-unique pairs will have a `None` entry.
3341-
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
3342-
&mut FxHashMap::default();
3341+
let unique_symbols_rev: &mut FxIndexMap<(Namespace, Symbol), Option<DefId>> =
3342+
&mut FxIndexMap::default();
33433343

33443344
for symbol_set in tcx.resolutions(()).glob_map.values() {
33453345
for symbol in symbol_set {
@@ -3350,7 +3350,7 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33503350
}
33513351

33523352
for_each_def(tcx, |ident, ns, def_id| {
3353-
use std::collections::hash_map::Entry::{Occupied, Vacant};
3353+
use indexmap::map::Entry::{Occupied, Vacant};
33543354

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

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

33753375
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 {

src/tools/clippy/tests/ui/wildcard_imports.fixed

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ extern crate wildcard_imports_helper;
1414

1515
use crate::fn_mod::foo;
1616
use crate::mod_mod::inner_mod;
17-
use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
17+
use crate::multi_fn_mod::{multi_foo, multi_bar, multi_inner_mod};
1818
#[macro_use]
1919
use crate::struct_mod::{A, inner_struct_mod};
2020

2121
#[allow(unused_imports)]
2222
use wildcard_imports_helper::inner::inner_for_self_import;
2323
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
24-
use wildcard_imports_helper::{ExternA, extern_foo};
24+
use wildcard_imports_helper::{extern_foo, ExternA};
2525

2626
use std::io::prelude::*;
2727
use wildcard_imports_helper::extern_prelude::v1::*;
@@ -129,7 +129,7 @@ mod in_fn_test {
129129

130130
fn test_extern() {
131131
use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
132-
use wildcard_imports_helper::{ExternA, extern_foo};
132+
use wildcard_imports_helper::{extern_foo, ExternA};
133133

134134
inner_for_self_import::inner_extern_foo();
135135
inner_extern_foo();
@@ -148,7 +148,7 @@ mod in_fn_test {
148148
}
149149

150150
fn test_extern_reexported() {
151-
use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
151+
use wildcard_imports_helper::{extern_exported, ExternExportedStruct, ExternExportedEnum};
152152

153153
extern_exported();
154154
let _ = ExternExportedStruct;
@@ -177,7 +177,7 @@ mod in_fn_test {
177177
}
178178

179179
fn test_reexported() {
180-
use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
180+
use crate::in_fn_test::{exported, ExportedStruct, ExportedEnum};
181181

182182
exported();
183183
let _ = ExportedStruct;

src/tools/clippy/tests/ui/wildcard_imports.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ error: usage of wildcard import
1717
--> tests/ui/wildcard_imports.rs:17:5
1818
|
1919
LL | use crate::multi_fn_mod::*;
20-
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
20+
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_foo, multi_bar, multi_inner_mod}`
2121

2222
error: usage of wildcard import
2323
--> tests/ui/wildcard_imports.rs:19:5
@@ -35,7 +35,7 @@ error: usage of wildcard import
3535
--> tests/ui/wildcard_imports.rs:24:5
3636
|
3737
LL | use wildcard_imports_helper::*;
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{extern_foo, ExternA}`
3939

4040
error: usage of wildcard import
4141
--> tests/ui/wildcard_imports.rs:94:13
@@ -59,7 +59,7 @@ error: usage of wildcard import
5959
--> tests/ui/wildcard_imports.rs:132:13
6060
|
6161
LL | use wildcard_imports_helper::*;
62-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
62+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{extern_foo, ExternA}`
6363

6464
error: usage of wildcard import
6565
--> tests/ui/wildcard_imports.rs:144:20
@@ -77,13 +77,13 @@ error: usage of wildcard import
7777
--> tests/ui/wildcard_imports.rs:151:13
7878
|
7979
LL | use wildcard_imports_helper::*;
80-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
80+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{extern_exported, ExternExportedStruct, ExternExportedEnum}`
8181

8282
error: usage of wildcard import
8383
--> tests/ui/wildcard_imports.rs:180:9
8484
|
8585
LL | use crate::in_fn_test::*;
86-
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
86+
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{exported, ExportedStruct, ExportedEnum}`
8787

8888
error: usage of wildcard import
8989
--> tests/ui/wildcard_imports.rs:189:9

0 commit comments

Comments
 (0)