Skip to content

Commit 8d221c5

Browse files
committed
Auto merge of #7027 - camsteffen:defidmap, r=phansch
Use DefIdMap and similar aliases changelog: none
2 parents e315437 + 6f31ed6 commit 8d221c5

File tree

10 files changed

+40
-40
lines changed

10 files changed

+40
-40
lines changed

clippy_lints/src/functions/must_use.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::ast::Attribute;
2-
use rustc_data_structures::fx::FxHashSet;
32
use rustc_errors::Applicability;
4-
use rustc_hir::{self as hir, def::Res, def_id::DefId, intravisit, QPath};
3+
use rustc_hir::def_id::DefIdSet;
4+
use rustc_hir::{self as hir, def::Res, intravisit, QPath};
55
use rustc_lint::{LateContext, LintContext};
66
use rustc_middle::{
77
hir::map::Map,
@@ -169,11 +169,11 @@ fn returns_unit(decl: &hir::FnDecl<'_>) -> bool {
169169
}
170170

171171
fn has_mutable_arg(cx: &LateContext<'_>, body: &hir::Body<'_>) -> bool {
172-
let mut tys = FxHashSet::default();
172+
let mut tys = DefIdSet::default();
173173
body.params.iter().any(|param| is_mutable_pat(cx, &param.pat, &mut tys))
174174
}
175175

176-
fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet<DefId>) -> bool {
176+
fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet) -> bool {
177177
if let hir::PatKind::Wild = pat.kind {
178178
return false; // ignore `_` patterns
179179
}
@@ -186,7 +186,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet<
186186

187187
static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]];
188188

189-
fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet<DefId>) -> bool {
189+
fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut DefIdSet) -> bool {
190190
match *ty.kind() {
191191
// primitive types are never mutable
192192
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
@@ -222,7 +222,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
222222
}
223223
match expr.kind {
224224
Call(_, args) | MethodCall(_, _, args, _) => {
225-
let mut tys = FxHashSet::default();
225+
let mut tys = DefIdSet::default();
226226
for arg in args {
227227
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
228228
&& is_mutable_ty(

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use rustc_data_structures::fx::FxHashSet;
2-
use rustc_hir::{self as hir, intravisit};
1+
use rustc_hir::{self as hir, intravisit, HirIdSet};
32
use rustc_lint::LateContext;
43
use rustc_middle::{hir::map::Map, ty};
54

@@ -44,7 +43,7 @@ fn check_raw_ptr(
4443
let raw_ptrs = iter_input_pats(decl, body)
4544
.zip(decl.inputs.iter())
4645
.filter_map(|(arg, ty)| raw_ptr_arg(arg, ty))
47-
.collect::<FxHashSet<_>>();
46+
.collect::<HirIdSet>();
4847

4948
if !raw_ptrs.is_empty() {
5049
let typeck_results = cx.tcx.typeck_body(body.id());
@@ -69,7 +68,7 @@ fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty<'_>) -> Option<hir::HirId> {
6968

7069
struct DerefVisitor<'a, 'tcx> {
7170
cx: &'a LateContext<'tcx>,
72-
ptrs: FxHashSet<hir::HirId>,
71+
ptrs: HirIdSet,
7372
typeck_results: &'a ty::TypeckResults<'tcx>,
7473
}
7574

clippy_lints/src/inherent_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::in_macro;
5-
use rustc_data_structures::fx::FxHashMap;
5+
use rustc_hir::def_id::DefIdMap;
66
use rustc_hir::{def_id, Crate, Impl, Item, ItemKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -43,7 +43,7 @@ declare_clippy_lint! {
4343
#[allow(clippy::module_name_repetitions)]
4444
#[derive(Default)]
4545
pub struct MultipleInherentImpl {
46-
impls: FxHashMap<def_id::DefId, Span>,
46+
impls: DefIdMap<Span>,
4747
}
4848

4949
impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);

clippy_lints/src/len_zero.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::{get_item_name, get_parent_as_impl, is_allowed};
44
use if_chain::if_chain;
55
use rustc_ast::ast::LitKind;
6-
use rustc_data_structures::fx::FxHashSet;
76
use rustc_errors::Applicability;
7+
use rustc_hir::def_id::DefIdSet;
88
use rustc_hir::{
99
def_id::DefId, AssocItemKind, BinOpKind, Expr, ExprKind, FnRetTy, ImplItem, ImplItemKind, ImplicitSelfKind, Item,
1010
ItemKind, Mutability, Node, TraitItemRef, TyKind,
@@ -199,7 +199,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
199199
}
200200

201201
// fill the set with current and super traits
202-
fn fill_trait_set(traitt: DefId, set: &mut FxHashSet<DefId>, cx: &LateContext<'_>) {
202+
fn fill_trait_set(traitt: DefId, set: &mut DefIdSet, cx: &LateContext<'_>) {
203203
if set.insert(traitt) {
204204
for supertrait in rustc_trait_selection::traits::supertrait_def_ids(cx.tcx, traitt) {
205205
fill_trait_set(supertrait, set, cx);
@@ -208,7 +208,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
208208
}
209209

210210
if cx.access_levels.is_exported(visited_trait.hir_id()) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
211-
let mut current_and_super_traits = FxHashSet::default();
211+
let mut current_and_super_traits = DefIdSet::default();
212212
fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx);
213213

214214
let is_empty_method_found = current_and_super_traits

clippy_lints/src/loops/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use clippy_utils::ty::{has_iter_method, implements_trait};
22
use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_local_id, sugg};
33
use if_chain::if_chain;
4-
use rustc_data_structures::fx::FxHashMap;
54
use rustc_errors::Applicability;
65
use rustc_hir::intravisit::{walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
6+
use rustc_hir::HirIdMap;
77
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Stmt, StmtKind};
88
use rustc_lint::LateContext;
99
use rustc_middle::hir::map::Map;
@@ -20,17 +20,17 @@ enum IncrementVisitorVarState {
2020

2121
/// Scan a for loop for variables that are incremented exactly once and not used after that.
2222
pub(super) struct IncrementVisitor<'a, 'tcx> {
23-
cx: &'a LateContext<'tcx>, // context reference
24-
states: FxHashMap<HirId, IncrementVisitorVarState>, // incremented variables
25-
depth: u32, // depth of conditional expressions
23+
cx: &'a LateContext<'tcx>, // context reference
24+
states: HirIdMap<IncrementVisitorVarState>, // incremented variables
25+
depth: u32, // depth of conditional expressions
2626
done: bool,
2727
}
2828

2929
impl<'a, 'tcx> IncrementVisitor<'a, 'tcx> {
3030
pub(super) fn new(cx: &'a LateContext<'tcx>) -> Self {
3131
Self {
3232
cx,
33-
states: FxHashMap::default(),
33+
states: HirIdMap::default(),
3434
depth: 0,
3535
done: false,
3636
}

clippy_lints/src/loops/while_immutable_condition.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use crate::consts::constant;
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::usage::mutated_variables;
55
use if_chain::if_chain;
6-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
76
use rustc_hir::def::{DefKind, Res};
7+
use rustc_hir::def_id::DefIdMap;
88
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
9-
use rustc_hir::{def_id, Expr, ExprKind, HirId, QPath};
9+
use rustc_hir::HirIdSet;
10+
use rustc_hir::{Expr, ExprKind, QPath};
1011
use rustc_lint::LateContext;
1112
use rustc_middle::hir::map::Map;
12-
use std::iter::Iterator;
1313

1414
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
1515
if constant(cx, cx.typeck_results(), cond).is_some() {
@@ -19,8 +19,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'
1919

2020
let mut var_visitor = VarCollectorVisitor {
2121
cx,
22-
ids: FxHashSet::default(),
23-
def_ids: FxHashMap::default(),
22+
ids: HirIdSet::default(),
23+
def_ids: DefIdMap::default(),
2424
skip: false,
2525
};
2626
var_visitor.visit_expr(cond);
@@ -93,8 +93,8 @@ impl<'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor {
9393
/// All variables definition IDs are collected
9494
struct VarCollectorVisitor<'a, 'tcx> {
9595
cx: &'a LateContext<'tcx>,
96-
ids: FxHashSet<HirId>,
97-
def_ids: FxHashMap<def_id::DefId, bool>,
96+
ids: HirIdSet,
97+
def_ids: DefIdMap<bool>,
9898
skip: bool,
9999
}
100100

clippy_lints/src/matches.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use clippy_utils::{
1313
use clippy_utils::{paths, search_same, SpanlessEq, SpanlessHash};
1414
use if_chain::if_chain;
1515
use rustc_ast::ast::LitKind;
16-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1716
use rustc_errors::Applicability;
1817
use rustc_hir::def::{CtorKind, DefKind, Res};
1918
use rustc_hir::{
2019
self as hir, Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Guard, HirId, Local, MatchSource,
2120
Mutability, Node, Pat, PatKind, PathSegment, QPath, RangeEnd, TyKind,
2221
};
22+
use rustc_hir::{HirIdMap, HirIdSet};
2323
use rustc_lint::{LateContext, LateLintPass, LintContext};
2424
use rustc_middle::lint::in_external_macro;
2525
use rustc_middle::ty::{self, Ty, TyS, VariantDef};
@@ -1980,7 +1980,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) {
19801980
let min_index = usize::min(lindex, rindex);
19811981
let max_index = usize::max(lindex, rindex);
19821982

1983-
let mut local_map: FxHashMap<HirId, HirId> = FxHashMap::default();
1983+
let mut local_map: HirIdMap<HirId> = HirIdMap::default();
19841984
let eq_fallback = |a: &Expr<'_>, b: &Expr<'_>| {
19851985
if_chain! {
19861986
if let Some(a_id) = path_to_local(a);
@@ -2064,7 +2064,7 @@ fn pat_contains_local(pat: &Pat<'_>, id: HirId) -> bool {
20642064
}
20652065

20662066
/// Returns true if all the bindings in the `Pat` are in `ids` and vice versa
2067-
fn bindings_eq(pat: &Pat<'_>, mut ids: FxHashSet<HirId>) -> bool {
2067+
fn bindings_eq(pat: &Pat<'_>, mut ids: HirIdSet) -> bool {
20682068
let mut result = true;
20692069
pat.each_binding_or_first(&mut |_, id, _, _| result &= ids.remove(&id));
20702070
result && ids.is_empty()

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item};
55
use clippy_utils::{get_trait_def_id, is_self, paths};
66
use if_chain::if_chain;
77
use rustc_ast::ast::Attribute;
8-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8+
use rustc_data_structures::fx::FxHashSet;
99
use rustc_errors::{Applicability, DiagnosticBuilder};
1010
use rustc_hir::intravisit::FnKind;
1111
use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Node, PatKind, QPath, TyKind};
12+
use rustc_hir::{HirIdMap, HirIdSet};
1213
use rustc_infer::infer::TyCtxtInferExt;
1314
use rustc_lint::{LateContext, LateLintPass};
1415
use rustc_middle::mir::FakeReadCause;
@@ -310,10 +311,10 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
310311

311312
#[derive(Default)]
312313
struct MovedVariablesCtxt {
313-
moved_vars: FxHashSet<HirId>,
314+
moved_vars: HirIdSet,
314315
/// Spans which need to be prefixed with `*` for dereferencing the
315316
/// suggested additional reference.
316-
spans_need_deref: FxHashMap<HirId, FxHashSet<Span>>,
317+
spans_need_deref: HirIdMap<FxHashSet<Span>>,
317318
}
318319

319320
impl MovedVariablesCtxt {

clippy_utils/src/hir_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::consts::{constant_context, constant_simple};
22
use crate::differing_macro_contexts;
33
use crate::source::snippet_opt;
44
use rustc_ast::ast::InlineAsmTemplatePiece;
5-
use rustc_data_structures::fx::FxHashMap;
65
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
76
use rustc_hir::def::Res;
7+
use rustc_hir::HirIdMap;
88
use rustc_hir::{
99
BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprField, ExprKind, FnRetTy, GenericArg,
1010
GenericArgs, Guard, HirId, InlineAsmOperand, Lifetime, LifetimeName, ParamName, Pat, PatField, PatKind, Path,
@@ -61,7 +61,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
6161
fn inter_expr(&mut self) -> HirEqInterExpr<'_, 'a, 'tcx> {
6262
HirEqInterExpr {
6363
inner: self,
64-
locals: FxHashMap::default(),
64+
locals: HirIdMap::default(),
6565
}
6666
}
6767

@@ -88,7 +88,7 @@ struct HirEqInterExpr<'a, 'b, 'tcx> {
8888
// When binding are declared, the binding ID in the left expression is mapped to the one on the
8989
// right. For example, when comparing `{ let x = 1; x + 2 }` and `{ let y = 1; y + 2 }`,
9090
// these blocks are considered equal since `x` is mapped to `y`.
91-
locals: FxHashMap<HirId, HirId>,
91+
locals: HirIdMap<HirId>,
9292
}
9393

9494
impl HirEqInterExpr<'_, '_, '_> {

clippy_utils/src/usage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate as utils;
2-
use rustc_data_structures::fx::FxHashSet;
32
use rustc_hir as hir;
43
use rustc_hir::def::Res;
54
use rustc_hir::intravisit;
65
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
6+
use rustc_hir::HirIdSet;
77
use rustc_hir::{Expr, ExprKind, HirId, Path};
88
use rustc_infer::infer::TyCtxtInferExt;
99
use rustc_lint::LateContext;
@@ -13,9 +13,9 @@ use rustc_middle::ty;
1313
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
1414

1515
/// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined.
16-
pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> Option<FxHashSet<HirId>> {
16+
pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> Option<HirIdSet> {
1717
let mut delegate = MutVarsDelegate {
18-
used_mutably: FxHashSet::default(),
18+
used_mutably: HirIdSet::default(),
1919
skip: false,
2020
};
2121
cx.tcx.infer_ctxt().enter(|infcx| {
@@ -44,7 +44,7 @@ pub fn is_potentially_mutated<'tcx>(variable: &'tcx Path<'_>, expr: &'tcx Expr<'
4444
}
4545

4646
struct MutVarsDelegate {
47-
used_mutably: FxHashSet<HirId>,
47+
used_mutably: HirIdSet,
4848
skip: bool,
4949
}
5050

0 commit comments

Comments
 (0)