Skip to content

Commit 7295b08

Browse files
committed
Auto merge of rust-lang#131160 - ismailarilik:handle-potential-query-instability-lint-for-rustc-middle, r=oli-obk
Handle `rustc_middle` cases of `rustc::potential_query_instability` lint This PR removes `#![allow(rustc::potential_query_instability)]` line from [`compiler/rustc_middle/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/lib.rs#L29) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors. A somewhat tracking issue: rust-lang#84447 r? `@compiler-errors`
2 parents 4a0969e + 2426dbc commit 7295b08

15 files changed

+54
-60
lines changed

compiler/rustc_middle/src/lib.rs

-1
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(bootstrap, feature(let_chains))]
3332
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ rustc_queries! {
22052205
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
22062206
desc { "fetching potentially unused trait imports" }
22072207
}
2208-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
2208+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxIndexSet<Symbol> {
22092209
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
22102210
}
22112211

compiler/rustc_middle/src/query/on_disk_cache.rs

+2-2
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

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_data_structures::steal::Steal;
2929
use rustc_data_structures::sync::{
3030
self, DynSend, DynSync, FreezeReadGuard, Lock, RwLock, WorkerLocal,
3131
};
32-
use rustc_data_structures::unord::UnordSet;
3332
use rustc_errors::{
3433
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, LintDiagnostic, MultiSpan,
3534
};
@@ -2423,6 +2422,8 @@ macro_rules! sty_debug_print {
24232422
$(let mut $variant = total;)*
24242423

24252424
for shard in tcx.interners.type_.lock_shards() {
2425+
// It seems that ordering doesn't affect anything here.
2426+
#[allow(rustc::potential_query_instability)]
24262427
let types = shard.iter();
24272428
for &(InternedInSet(t), ()) in types {
24282429
let variant = match t.internee {
@@ -3413,9 +3414,7 @@ pub fn provide(providers: &mut Providers) {
34133414
providers.maybe_unused_trait_imports =
34143415
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
34153416
providers.names_imported_by_glob_use = |tcx, id| {
3416-
tcx.arena.alloc(UnordSet::from(
3417-
tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(),
3418-
))
3417+
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
34193418
};
34203419

34213420
providers.extern_mod_stmt_cnum =

compiler/rustc_middle/src/ty/diagnostics.rs

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub struct ResolverGlobalCtxt {
182182
pub extern_crate_map: UnordMap<LocalDefId, CrateNum>,
183183
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
184184
pub module_children: LocalDefIdMap<Vec<ModChild>>,
185-
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
185+
pub glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
186186
pub main_def: Option<MainDefinition>,
187187
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
188188
/// 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
@@ -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;
@@ -3497,8 +3497,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
34973497

34983498
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
34993499
// non-unique pairs will have a `None` entry.
3500-
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
3501-
&mut FxHashMap::default();
3500+
let unique_symbols_rev: &mut FxIndexMap<(Namespace, Symbol), Option<DefId>> =
3501+
&mut FxIndexMap::default();
35023502

35033503
for symbol_set in tcx.resolutions(()).glob_map.values() {
35043504
for symbol in symbol_set {
@@ -3508,27 +3508,23 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
35083508
}
35093509
}
35103510

3511-
for_each_def(tcx, |ident, ns, def_id| {
3512-
use std::collections::hash_map::Entry::{Occupied, Vacant};
3513-
3514-
match unique_symbols_rev.entry((ns, ident.name)) {
3515-
Occupied(mut v) => match v.get() {
3516-
None => {}
3517-
Some(existing) => {
3518-
if *existing != def_id {
3519-
v.insert(None);
3520-
}
3511+
for_each_def(tcx, |ident, ns, def_id| match unique_symbols_rev.entry((ns, ident.name)) {
3512+
IndexEntry::Occupied(mut v) => match v.get() {
3513+
None => {}
3514+
Some(existing) => {
3515+
if *existing != def_id {
3516+
v.insert(None);
35213517
}
3522-
},
3523-
Vacant(v) => {
3524-
v.insert(Some(def_id));
35253518
}
3519+
},
3520+
IndexEntry::Vacant(v) => {
3521+
v.insert(Some(def_id));
35263522
}
35273523
});
35283524

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

35343530
if let Some(def_id) = opt_def_id {

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ pub struct Resolver<'ra, 'tcx> {
10991099
underscore_disambiguator: u32,
11001100

11011101
/// Maps glob imports to the names of items actually imported.
1102-
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
1102+
glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
11031103
glob_error: Option<ErrorGuaranteed>,
11041104
visibilities_for_hashing: Vec<(LocalDefId, ty::Visibility)>,
11051105
used_imports: FxHashSet<NodeId>,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl LateLintPass<'_> for WildcardImports {
154154
(span, false)
155155
};
156156

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

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::fn_mod::foo;
1616
//~^ wildcard_imports
1717
use crate::mod_mod::inner_mod;
1818
//~^ wildcard_imports
19-
use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
19+
use crate::multi_fn_mod::{multi_foo, multi_bar, multi_inner_mod};
2020
//~^ wildcard_imports
2121
#[macro_use]
2222
use crate::struct_mod::{A, inner_struct_mod};
@@ -26,7 +26,7 @@ use crate::struct_mod::{A, inner_struct_mod};
2626
use wildcard_imports_helper::inner::inner_for_self_import;
2727
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
2828
//~^ wildcard_imports
29-
use wildcard_imports_helper::{ExternA, extern_foo};
29+
use wildcard_imports_helper::{extern_foo, ExternA};
3030
//~^ wildcard_imports
3131

3232
use std::io::prelude::*;
@@ -138,7 +138,7 @@ mod in_fn_test {
138138
fn test_extern() {
139139
use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
140140
//~^ wildcard_imports
141-
use wildcard_imports_helper::{ExternA, extern_foo};
141+
use wildcard_imports_helper::{extern_foo, ExternA};
142142
//~^ wildcard_imports
143143

144144
inner_for_self_import::inner_extern_foo();
@@ -160,7 +160,7 @@ mod in_fn_test {
160160
}
161161

162162
fn test_extern_reexported() {
163-
use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
163+
use wildcard_imports_helper::{extern_exported, ExternExportedStruct, ExternExportedEnum};
164164
//~^ wildcard_imports
165165

166166
extern_exported();
@@ -190,7 +190,7 @@ mod in_fn_test {
190190
}
191191

192192
fn test_reexported() {
193-
use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
193+
use crate::in_fn_test::{exported, ExportedStruct, ExportedEnum};
194194
//~^ wildcard_imports
195195

196196
exported();

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:19: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:22:5
@@ -35,7 +35,7 @@ error: usage of wildcard import
3535
--> tests/ui/wildcard_imports.rs:29: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:100:13
@@ -59,7 +59,7 @@ error: usage of wildcard import
5959
--> tests/ui/wildcard_imports.rs:141: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:154:20
@@ -77,13 +77,13 @@ error: usage of wildcard import
7777
--> tests/ui/wildcard_imports.rs:163: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:193: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:203:9

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::fn_mod::foo;
1414
//~^ wildcard_imports
1515
use crate::mod_mod::inner_mod;
1616
//~^ wildcard_imports
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
//~^ wildcard_imports
1919
use crate::struct_mod::{A, inner_struct_mod};
2020
//~^ wildcard_imports
@@ -23,7 +23,7 @@ use crate::struct_mod::{A, inner_struct_mod};
2323
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
2424
//~^ wildcard_imports
2525
use wildcard_imports_helper::prelude::v1::*;
26-
use wildcard_imports_helper::{ExternA, extern_foo};
26+
use wildcard_imports_helper::{extern_foo, ExternA};
2727
//~^ wildcard_imports
2828

2929
use std::io::prelude::*;
@@ -132,7 +132,7 @@ mod in_fn_test {
132132
fn test_extern() {
133133
use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
134134
//~^ wildcard_imports
135-
use wildcard_imports_helper::{ExternA, extern_foo};
135+
use wildcard_imports_helper::{extern_foo, ExternA};
136136
//~^ wildcard_imports
137137

138138
inner_for_self_import::inner_extern_foo();
@@ -154,7 +154,7 @@ mod in_fn_test {
154154
}
155155

156156
fn test_extern_reexported() {
157-
use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
157+
use wildcard_imports_helper::{extern_exported, ExternExportedStruct, ExternExportedEnum};
158158
//~^ wildcard_imports
159159

160160
extern_exported();
@@ -184,7 +184,7 @@ mod in_fn_test {
184184
}
185185

186186
fn test_reexported() {
187-
use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
187+
use crate::in_fn_test::{exported, ExportedStruct, ExportedEnum};
188188
//~^ wildcard_imports
189189

190190
exported();

src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.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_2021.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_2021.rs:19:5
@@ -35,7 +35,7 @@ error: usage of wildcard import
3535
--> tests/ui/wildcard_imports_2021.rs:26: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_2021.rs:95:13
@@ -59,7 +59,7 @@ error: usage of wildcard import
5959
--> tests/ui/wildcard_imports_2021.rs:135: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_2021.rs:148:20
@@ -77,13 +77,13 @@ error: usage of wildcard import
7777
--> tests/ui/wildcard_imports_2021.rs:157: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_2021.rs:187: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_2021.rs:197:9

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::fn_mod::foo;
1414
//~^ wildcard_imports
1515
use crate::mod_mod::inner_mod;
1616
//~^ wildcard_imports
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
//~^ wildcard_imports
1919
use crate::struct_mod::{A, inner_struct_mod};
2020
//~^ wildcard_imports
@@ -23,7 +23,7 @@ use crate::struct_mod::{A, inner_struct_mod};
2323
use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
2424
//~^ wildcard_imports
2525
use wildcard_imports_helper::prelude::v1::*;
26-
use wildcard_imports_helper::{ExternA, extern_foo};
26+
use wildcard_imports_helper::{extern_foo, ExternA};
2727
//~^ wildcard_imports
2828

2929
use std::io::prelude::*;
@@ -132,7 +132,7 @@ mod in_fn_test {
132132
fn test_extern() {
133133
use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
134134
//~^ wildcard_imports
135-
use wildcard_imports_helper::{ExternA, extern_foo};
135+
use wildcard_imports_helper::{extern_foo, ExternA};
136136
//~^ wildcard_imports
137137

138138
inner_for_self_import::inner_extern_foo();
@@ -154,7 +154,7 @@ mod in_fn_test {
154154
}
155155

156156
fn test_extern_reexported() {
157-
use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
157+
use wildcard_imports_helper::{extern_exported, ExternExportedStruct, ExternExportedEnum};
158158
//~^ wildcard_imports
159159

160160
extern_exported();
@@ -184,7 +184,7 @@ mod in_fn_test {
184184
}
185185

186186
fn test_reexported() {
187-
use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
187+
use crate::in_fn_test::{exported, ExportedStruct, ExportedEnum};
188188
//~^ wildcard_imports
189189

190190
exported();

0 commit comments

Comments
 (0)