Skip to content

Commit 01e27a3

Browse files
committed
Handle rustc_middle cases of rustc::potential_query_instability lint
1 parent 66701c4 commit 01e27a3

16 files changed

+64
-71
lines changed

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/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
@@ -1939,7 +1939,7 @@ rustc_queries! {
19391939
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
19401940
desc { "fetching potentially unused trait imports" }
19411941
}
1942-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
1942+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxIndexSet<Symbol> {
19431943
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
19441944
}
19451945

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
@@ -19,13 +19,12 @@ use rustc_data_structures::fingerprint::Fingerprint;
1919
use rustc_data_structures::fx::FxHashMap;
2020
use rustc_data_structures::intern::Interned;
2121
use rustc_data_structures::profiling::SelfProfilerRef;
22-
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
22+
use rustc_data_structures::sharded::{IntoPointer, ShardedIndexMap};
2323
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2424
use rustc_data_structures::steal::Steal;
2525
use rustc_data_structures::sync::{self, FreezeReadGuard, Lock, Lrc, RwLock, WorkerLocal};
2626
#[cfg(parallel_compiler)]
2727
use rustc_data_structures::sync::{DynSend, DynSync};
28-
use rustc_data_structures::unord::UnordSet;
2928
use rustc_errors::{
3029
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, LintDiagnostic, MultiSpan,
3130
};
@@ -743,7 +742,7 @@ impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
743742
}
744743
}
745744

746-
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
745+
type InternedSet<'tcx, T> = ShardedIndexMap<InternedInSet<'tcx, T>, ()>;
747746

748747
pub struct CtxtInterners<'tcx> {
749748
/// The arena that types, regions, etc. are allocated from.
@@ -3227,9 +3226,7 @@ pub fn provide(providers: &mut Providers) {
32273226
providers.maybe_unused_trait_imports =
32283227
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
32293228
providers.names_imported_by_glob_use = |tcx, id| {
3230-
tcx.arena.alloc(UnordSet::from(
3231-
tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(),
3232-
))
3229+
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
32333230
};
32343231

32353232
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;
@@ -277,7 +277,7 @@ pub fn suggest_constraining_type_params<'a>(
277277
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
278278
span_to_replace: Option<Span>,
279279
) -> bool {
280-
let mut grouped = FxHashMap::default();
280+
let mut grouped = FxIndexMap::default();
281281
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
282282
grouped.entry(param_name).or_insert(Vec::new()).push((constraint, def_id))
283283
});

compiler/rustc_middle/src/ty/mod.rs

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

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

+13-17
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, IndexEntry};
99
use rustc_data_structures::unord::UnordMap;
1010
use rustc_hir as hir;
1111
use rustc_hir::LangItem;
@@ -3352,8 +3352,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33523352

33533353
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
33543354
// non-unique pairs will have a `None` entry.
3355-
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
3356-
&mut FxHashMap::default();
3355+
let unique_symbols_rev: &mut FxIndexMap<(Namespace, Symbol), Option<DefId>> =
3356+
&mut FxIndexMap::default();
33573357

33583358
for symbol_set in tcx.resolutions(()).glob_map.values() {
33593359
for symbol in symbol_set {
@@ -3363,27 +3363,23 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
33633363
}
33643364
}
33653365

3366-
for_each_def(tcx, |ident, ns, def_id| {
3367-
use std::collections::hash_map::Entry::{Occupied, Vacant};
3368-
3369-
match unique_symbols_rev.entry((ns, ident.name)) {
3370-
Occupied(mut v) => match v.get() {
3371-
None => {}
3372-
Some(existing) => {
3373-
if *existing != def_id {
3374-
v.insert(None);
3375-
}
3366+
for_each_def(tcx, |ident, ns, def_id| match unique_symbols_rev.entry((ns, ident.name)) {
3367+
IndexEntry::Occupied(mut v) => match v.get() {
3368+
None => {}
3369+
Some(existing) => {
3370+
if *existing != def_id {
3371+
v.insert(None);
33763372
}
3377-
},
3378-
Vacant(v) => {
3379-
v.insert(Some(def_id));
33803373
}
3374+
},
3375+
IndexEntry::Vacant(v) => {
3376+
v.insert(Some(def_id));
33813377
}
33823378
});
33833379

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

33893385
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

src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ extern crate wildcard_imports_helper;
1212

1313
use crate::fn_mod::foo;
1414
use crate::mod_mod::inner_mod;
15-
use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
15+
use crate::multi_fn_mod::{multi_foo, multi_bar, multi_inner_mod};
1616
use crate::struct_mod::{A, inner_struct_mod};
1717

1818
#[allow(unused_imports)]
1919
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
2020
use wildcard_imports_helper::prelude::v1::*;
21-
use wildcard_imports_helper::{ExternA, extern_foo};
21+
use wildcard_imports_helper::{extern_foo, ExternA};
2222

2323
use std::io::prelude::*;
2424

@@ -123,7 +123,7 @@ mod in_fn_test {
123123

124124
fn test_extern() {
125125
use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
126-
use wildcard_imports_helper::{ExternA, extern_foo};
126+
use wildcard_imports_helper::{extern_foo, ExternA};
127127

128128
inner_for_self_import::inner_extern_foo();
129129
inner_extern_foo();
@@ -142,7 +142,7 @@ mod in_fn_test {
142142
}
143143

144144
fn test_extern_reexported() {
145-
use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
145+
use wildcard_imports_helper::{extern_exported, ExternExportedStruct, ExternExportedEnum};
146146

147147
extern_exported();
148148
let _ = ExternExportedStruct;
@@ -171,7 +171,7 @@ mod in_fn_test {
171171
}
172172

173173
fn test_reexported() {
174-
use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
174+
use crate::in_fn_test::{exported, ExportedStruct, ExportedEnum};
175175

176176
exported();
177177
let _ = ExportedStruct;

0 commit comments

Comments
 (0)