Skip to content

Commit b1c4684

Browse files
authored
Rollup merge of #131277 - ismailarilik:handle-potential-query-instability-lint-for-clippy, r=xFrednet
Handle `clippy` cases of `rustc::potential_query_instability` lint This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors. A somewhat tracking issue: rust-lang/rust#84447
2 parents f5cc292 + 0b632ec commit b1c4684

10 files changed

+32
-34
lines changed

clippy_lints/src/index_refutable_slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
55
use clippy_utils::higher::IfLet;
66
use clippy_utils::ty::is_copy;
77
use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local};
8-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
8+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
99
use rustc_errors::Applicability;
1010
use rustc_hir as hir;
1111
use rustc_hir::HirId;
@@ -133,7 +133,7 @@ fn lint_slice(cx: &LateContext<'_>, slice: &SliceLintInformation) {
133133
.index_use
134134
.iter()
135135
.map(|(index, _)| *index)
136-
.collect::<FxHashSet<_>>();
136+
.collect::<FxIndexSet<_>>();
137137

138138
let value_name = |index| format!("{}_{index}", slice.ident.name);
139139

clippy_lints/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
unused_qualifications,
2727
rustc::internal
2828
)]
29-
// Disable this rustc lint for now, as it was also done in rustc
30-
#![allow(rustc::potential_query_instability)]
3129

3230
// FIXME: switch to something more ergonomic here, once available.
3331
// (Currently there is no way to opt into sysroot crates without `extern crate`.)

clippy_lints/src/lifetimes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
22
use clippy_utils::trait_ref_of_method;
33
use itertools::Itertools;
4-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
55
use rustc_errors::Applicability;
66
use rustc_hir::FnRetTy::Return;
77
use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter};
@@ -311,7 +311,7 @@ fn could_use_elision<'tcx>(
311311
Some((elidable_lts, usages))
312312
}
313313

314-
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet<LocalDefId> {
314+
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxIndexSet<LocalDefId> {
315315
named_generics
316316
.iter()
317317
.filter_map(|par| {
@@ -497,7 +497,7 @@ struct Usage {
497497

498498
struct LifetimeChecker<'cx, 'tcx, F> {
499499
cx: &'cx LateContext<'tcx>,
500-
map: FxHashMap<LocalDefId, Vec<Usage>>,
500+
map: FxIndexMap<LocalDefId, Vec<Usage>>,
501501
where_predicate_depth: usize,
502502
generic_args_depth: usize,
503503
phantom: std::marker::PhantomData<F>,
@@ -619,7 +619,7 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'
619619
fn report_elidable_impl_lifetimes<'tcx>(
620620
cx: &LateContext<'tcx>,
621621
impl_: &'tcx Impl<'_>,
622-
map: &FxHashMap<LocalDefId, Vec<Usage>>,
622+
map: &FxIndexMap<LocalDefId, Vec<Usage>>,
623623
) {
624624
let single_usages = map
625625
.iter()

clippy_lints/src/loops/needless_range_loop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::ty::has_iter_method;
55
use clippy_utils::visitors::is_local_used;
66
use clippy_utils::{SpanlessEq, contains_name, higher, is_integer_const, sugg};
77
use rustc_ast::ast;
8-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
99
use rustc_errors::Applicability;
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{Visitor, walk_expr};
@@ -39,7 +39,7 @@ pub(super) fn check<'tcx>(
3939
var: canonical_id,
4040
indexed_mut: FxHashSet::default(),
4141
indexed_indirectly: FxHashMap::default(),
42-
indexed_directly: FxHashMap::default(),
42+
indexed_directly: FxIndexMap::default(),
4343
referenced: FxHashSet::default(),
4444
nonindex: false,
4545
prefer_mutable: false,
@@ -229,7 +229,7 @@ struct VarVisitor<'a, 'tcx> {
229229
indexed_indirectly: FxHashMap<Symbol, Option<region::Scope>>,
230230
/// subset of `indexed` of vars that are indexed directly: `v[i]`
231231
/// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]`
232-
indexed_directly: FxHashMap<Symbol, (Option<region::Scope>, Ty<'tcx>)>,
232+
indexed_directly: FxIndexMap<Symbol, (Option<region::Scope>, Ty<'tcx>)>,
233233
/// Any names that are used outside an index operation.
234234
/// Used to detect things like `&mut vec` used together with `vec[i]`
235235
referenced: FxHashSet<Symbol>,

clippy_lints/src/matches/significant_drop_in_scrutinee.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use clippy_utils::ty::{for_each_top_level_late_bound_region, is_copy};
77
use clippy_utils::{get_attr, is_lint_allowed};
88
use itertools::Itertools;
99
use rustc_ast::Mutability;
10+
use rustc_data_structures::fx::FxIndexSet;
1011
use rustc_errors::{Applicability, Diag};
1112
use rustc_hir::intravisit::{Visitor, walk_expr};
1213
use rustc_hir::{Arm, Expr, ExprKind, MatchSource};
@@ -475,19 +476,19 @@ impl<'tcx> Visitor<'tcx> for SigDropHelper<'_, 'tcx> {
475476

476477
struct ArmSigDropHelper<'a, 'tcx> {
477478
sig_drop_checker: SigDropChecker<'a, 'tcx>,
478-
found_sig_drop_spans: FxHashSet<Span>,
479+
found_sig_drop_spans: FxIndexSet<Span>,
479480
}
480481

481482
impl<'a, 'tcx> ArmSigDropHelper<'a, 'tcx> {
482483
fn new(cx: &'a LateContext<'tcx>) -> ArmSigDropHelper<'a, 'tcx> {
483484
ArmSigDropHelper {
484485
sig_drop_checker: SigDropChecker::new(cx),
485-
found_sig_drop_spans: FxHashSet::<Span>::default(),
486+
found_sig_drop_spans: FxIndexSet::<Span>::default(),
486487
}
487488
}
488489
}
489490

490-
fn has_significant_drop_in_arms<'tcx>(cx: &LateContext<'tcx>, arms: &[&'tcx Expr<'_>]) -> FxHashSet<Span> {
491+
fn has_significant_drop_in_arms<'tcx>(cx: &LateContext<'tcx>, arms: &[&'tcx Expr<'_>]) -> FxIndexSet<Span> {
491492
let mut helper = ArmSigDropHelper::new(cx);
492493
for arm in arms {
493494
helper.visit_expr(arm);

clippy_lints/src/missing_asserts_for_indexing.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::visitors::for_each_expr_without_closures;
88
use clippy_utils::{eq_expr_value, hash_expr, higher};
99
use rustc_ast::{LitKind, RangeLimits};
1010
use rustc_data_structures::packed::Pu128;
11-
use rustc_data_structures::unhash::UnhashMap;
11+
use rustc_data_structures::unhash::UnindexMap;
1212
use rustc_errors::{Applicability, Diag};
1313
use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp};
1414
use rustc_lint::{LateContext, LateLintPass};
@@ -226,7 +226,7 @@ fn upper_index_expr(expr: &Expr<'_>) -> Option<usize> {
226226
}
227227

228228
/// Checks if the expression is an index into a slice and adds it to `indexes`
229-
fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnhashMap<u64, Vec<IndexEntry<'hir>>>) {
229+
fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnindexMap<u64, Vec<IndexEntry<'hir>>>) {
230230
if let ExprKind::Index(slice, index_lit, _) = expr.kind
231231
&& cx.typeck_results().expr_ty_adjusted(slice).peel_refs().is_slice()
232232
&& let Some(index) = upper_index_expr(index_lit)
@@ -274,7 +274,7 @@ fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut Unh
274274
}
275275

276276
/// Checks if the expression is an `assert!` expression and adds it to `asserts`
277-
fn check_assert<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnhashMap<u64, Vec<IndexEntry<'hir>>>) {
277+
fn check_assert<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnindexMap<u64, Vec<IndexEntry<'hir>>>) {
278278
if let Some((comparison, asserted_len, slice)) = assert_len_expr(cx, expr) {
279279
let hash = hash_expr(cx, slice);
280280
let indexes = map.entry(hash).or_default();
@@ -311,7 +311,7 @@ fn check_assert<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut Un
311311
/// Inspects indexes and reports lints.
312312
///
313313
/// Called at the end of this lint after all indexing and `assert!` expressions have been collected.
314-
fn report_indexes(cx: &LateContext<'_>, map: &UnhashMap<u64, Vec<IndexEntry<'_>>>) {
314+
fn report_indexes(cx: &LateContext<'_>, map: &UnindexMap<u64, Vec<IndexEntry<'_>>>) {
315315
for bucket in map.values() {
316316
for entry in bucket {
317317
let Some(full_span) = entry
@@ -403,7 +403,7 @@ fn report_indexes(cx: &LateContext<'_>, map: &UnhashMap<u64, Vec<IndexEntry<'_>>
403403

404404
impl LateLintPass<'_> for MissingAssertsForIndexing {
405405
fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
406-
let mut map = UnhashMap::default();
406+
let mut map = UnindexMap::default();
407407

408408
for_each_expr_without_closures(body.value, |expr| {
409409
check_index(cx, expr, &mut map);

clippy_lints/src/module_style.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_ast::ast;
3-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
44
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
55
use rustc_session::impl_lint_pass;
66
use rustc_span::def_id::LOCAL_CRATE;
@@ -87,7 +87,7 @@ impl EarlyLintPass for ModStyle {
8787

8888
// `folder_segments` is all unique folder path segments `path/to/foo.rs` gives
8989
// `[path, to]` but not foo
90-
let mut folder_segments = FxHashSet::default();
90+
let mut folder_segments = FxIndexSet::default();
9191
// `mod_folders` is all the unique folder names that contain a mod.rs file
9292
let mut mod_folders = FxHashSet::default();
9393
// `file_map` maps file names to the full path including the file name
@@ -144,7 +144,7 @@ impl EarlyLintPass for ModStyle {
144144
/// is `mod.rs` we add it's parent folder to `mod_folders`.
145145
fn process_paths_for_mod_files<'a>(
146146
path: &'a Path,
147-
folder_segments: &mut FxHashSet<&'a OsStr>,
147+
folder_segments: &mut FxIndexSet<&'a OsStr>,
148148
mod_folders: &mut FxHashSet<&'a OsStr>,
149149
) {
150150
let mut comp = path.components().rev().peekable();

clippy_lints/src/needless_pass_by_ref_mut.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::source::snippet;
55
use clippy_utils::visitors::for_each_expr;
66
use clippy_utils::{inherits_cfg, is_from_proc_macro, is_self};
77
use core::ops::ControlFlow;
8-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
8+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
99
use rustc_errors::Applicability;
1010
use rustc_hir::intravisit::FnKind;
1111
use rustc_hir::{
@@ -101,7 +101,7 @@ fn check_closures<'tcx>(
101101
ctx: &mut MutablyUsedVariablesCtxt<'tcx>,
102102
cx: &LateContext<'tcx>,
103103
checked_closures: &mut FxHashSet<LocalDefId>,
104-
closures: FxHashSet<LocalDefId>,
104+
closures: FxIndexSet<LocalDefId>,
105105
) {
106106
let hir = cx.tcx.hir();
107107
for closure in closures {
@@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
196196
prev_bind: None,
197197
prev_move_to_closure: HirIdSet::default(),
198198
aliases: HirIdMap::default(),
199-
async_closures: FxHashSet::default(),
199+
async_closures: FxIndexSet::default(),
200200
tcx: cx.tcx,
201201
};
202202
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx)
@@ -207,7 +207,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
207207

208208
// We retrieve all the closures declared in the function because they will not be found
209209
// by `euv::Delegate`.
210-
let mut closures: FxHashSet<LocalDefId> = FxHashSet::default();
210+
let mut closures: FxIndexSet<LocalDefId> = FxIndexSet::default();
211211
for_each_expr(cx, body, |expr| {
212212
if let ExprKind::Closure(closure) = expr.kind {
213213
closures.insert(closure.def_id);
@@ -307,7 +307,7 @@ struct MutablyUsedVariablesCtxt<'tcx> {
307307
/// use of a variable.
308308
prev_move_to_closure: HirIdSet,
309309
aliases: HirIdMap<HirId>,
310-
async_closures: FxHashSet<LocalDefId>,
310+
async_closures: FxIndexSet<LocalDefId>,
311311
tcx: TyCtxt<'tcx>,
312312
}
313313

clippy_lints/src/swap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use clippy_utils::ty::is_type_diagnostic_item;
66
use clippy_utils::{can_mut_borrow_both, eq_expr_value, is_in_const_context, std_or_core};
77
use itertools::Itertools;
88

9+
use rustc_data_structures::fx::FxIndexSet;
910
use rustc_hir::intravisit::{Visitor, walk_expr};
1011

11-
use crate::FxHashSet;
1212
use rustc_errors::Applicability;
1313
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, LetStmt, PatKind, QPath, Stmt, StmtKind};
1414
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -334,7 +334,7 @@ struct IndexBinding<'a, 'tcx> {
334334

335335
impl<'tcx> IndexBinding<'_, 'tcx> {
336336
fn snippet_index_bindings(&mut self, exprs: &[&'tcx Expr<'tcx>]) -> String {
337-
let mut bindings = FxHashSet::default();
337+
let mut bindings = FxIndexSet::default();
338338
for expr in exprs {
339339
bindings.insert(self.snippet_index_binding(expr));
340340
}

clippy_lints/src/trait_bounds.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::source::{SpanRangeExt, snippet, snippet_with_applicability};
55
use clippy_utils::{SpanlessEq, SpanlessHash, is_from_proc_macro};
66
use core::hash::{Hash, Hasher};
77
use itertools::Itertools;
8-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, IndexEntry};
99
use rustc_data_structures::unhash::UnhashMap;
1010
use rustc_errors::Applicability;
1111
use rustc_hir::def::Res;
@@ -16,7 +16,6 @@ use rustc_hir::{
1616
use rustc_lint::{LateContext, LateLintPass};
1717
use rustc_session::impl_lint_pass;
1818
use rustc_span::{BytePos, Span};
19-
use std::collections::hash_map::Entry;
2019

2120
declare_clippy_lint! {
2221
/// ### What it does
@@ -427,7 +426,7 @@ fn rollup_traits(
427426
bounds: &[GenericBound<'_>],
428427
msg: &'static str,
429428
) -> Vec<(ComparableTraitRef, Span)> {
430-
let mut map = FxHashMap::default();
429+
let mut map = FxIndexMap::default();
431430
let mut repeated_res = false;
432431

433432
let only_comparable_trait_refs = |bound: &GenericBound<'_>| {
@@ -442,8 +441,8 @@ fn rollup_traits(
442441
for bound in bounds.iter().filter_map(only_comparable_trait_refs) {
443442
let (comparable_bound, span_direct) = bound;
444443
match map.entry(comparable_bound) {
445-
Entry::Occupied(_) => repeated_res = true,
446-
Entry::Vacant(e) => {
444+
IndexEntry::Occupied(_) => repeated_res = true,
445+
IndexEntry::Vacant(e) => {
447446
e.insert((span_direct, i));
448447
i += 1;
449448
},

0 commit comments

Comments
 (0)