Skip to content

Commit

Permalink
Avoid lots of hir::HirId{,Map,Set} qualifiers.
Browse files Browse the repository at this point in the history
Because they're a bit redundant.
  • Loading branch information
nnethercote committed Apr 16, 2024
1 parent c0bc812 commit 0aea3ed
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_hir::{self as hir, intravisit, HirIdSet};
use rustc_hir::{self as hir, intravisit, HirId, HirIdSet};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::def_id::LocalDefId;
Expand Down Expand Up @@ -74,7 +74,7 @@ fn check_raw_ptr<'tcx>(
}
}

fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId> {
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<HirId> {
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
&arg.pat.kind,
cx.maybe_typeck_results()
Expand Down
13 changes: 7 additions & 6 deletions clippy_lints/src/index_refutable_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::HirId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter;
Expand Down Expand Up @@ -87,9 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
extract_msrv_attr!(LateContext);
}

fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir::HirId, SliceLintInformation> {
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default();
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default();
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<HirId, SliceLintInformation> {
let mut removed_pat: FxHashSet<HirId> = FxHashSet::default();
let mut slices: FxIndexMap<HirId, SliceLintInformation> = FxIndexMap::default();
pat.walk_always(|pat| {
// We'll just ignore mut and ref mut for simplicity sake right now
if let hir::PatKind::Binding(
Expand Down Expand Up @@ -206,10 +207,10 @@ impl SliceLintInformation {

fn filter_lintable_slices<'tcx>(
cx: &LateContext<'tcx>,
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
max_suggested_slice: u64,
scope: &'tcx hir::Expr<'tcx>,
) -> FxIndexMap<hir::HirId, SliceLintInformation> {
) -> FxIndexMap<HirId, SliceLintInformation> {
let mut visitor = SliceIndexLintingVisitor {
cx,
slice_lint_info,
Expand All @@ -223,7 +224,7 @@ fn filter_lintable_slices<'tcx>(

struct SliceIndexLintingVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
max_suggested_slice: u64,
}

Expand Down
33 changes: 17 additions & 16 deletions clippy_lints/src/operators/assign_op_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use clippy_utils::{binop_traits, eq_expr_value, trait_ref_of_method};
use core::ops::ControlFlow;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::{HirId, HirIdSet};
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_lint::LateContext;
use rustc_middle::mir::FakeReadCause;
Expand Down Expand Up @@ -98,10 +99,10 @@ pub(super) fn check<'tcx>(
}
}

fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet {
struct S(hir::HirIdSet);
fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
struct S(HirIdSet);
impl Delegate<'_> for S {
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) {
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) {
self.0.insert(match place.place.base {
PlaceBase::Local(id) => id,
Expand All @@ -111,13 +112,13 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
}
}

fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {}
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
}

let mut s = S(hir::HirIdSet::default());
let mut s = S(HirIdSet::default());
let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new(
&mut s,
Expand All @@ -130,10 +131,10 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
s.0
}

fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet {
struct S(hir::HirIdSet);
fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
struct S(HirIdSet);
impl Delegate<'_> for S {
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) {
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
if matches!(kind, BorrowKind::MutBorrow) {
self.0.insert(match place.place.base {
PlaceBase::Local(id) => id,
Expand All @@ -143,13 +144,13 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
}
}

fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {}
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
}

let mut s = S(hir::HirIdSet::default());
let mut s = S(HirIdSet::default());
let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new(
&mut s,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_i
use hir::LifetimeName;
use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::def_id::DefId;
use rustc_hir::hir_id::HirIdMap;
use rustc_hir::hir_id::{HirId, HirIdMap};
use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{
self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg,
Expand Down Expand Up @@ -324,7 +324,7 @@ struct PtrArgReplacement {

struct PtrArg<'tcx> {
idx: usize,
emission_id: hir::HirId,
emission_id: HirId,
span: Span,
ty_did: DefId,
ty_name: Symbol,
Expand Down
18 changes: 9 additions & 9 deletions clippy_lints/src/significant_drop_tightening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{self as hir};
use rustc_hir::{self as hir, HirId};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::{GenericArgKind, Ty};
use rustc_session::impl_lint_pass;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl_lint_pass!(SignificantDropTightening<'_> => [SIGNIFICANT_DROP_TIGHTENING]);

#[derive(Default)]
pub struct SignificantDropTightening<'tcx> {
apas: FxIndexMap<hir::HirId, AuxParamsAttr>,
apas: FxIndexMap<HirId, AuxParamsAttr>,
/// Auxiliary structure used to avoid having to verify the same type multiple times.
seen_types: FxHashSet<Ty<'tcx>>,
type_cache: FxHashMap<Ty<'tcx>, bool>,
Expand Down Expand Up @@ -359,20 +359,20 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
/// Auxiliary parameters used on each block check of an item
struct AuxParams<'others, 'stmt, 'tcx> {
//// See [AuxParamsAttr].
apas: &'others mut FxIndexMap<hir::HirId, AuxParamsAttr>,
apas: &'others mut FxIndexMap<HirId, AuxParamsAttr>,
/// The current block identifier that is being visited.
curr_block_hir_id: hir::HirId,
curr_block_hir_id: HirId,
/// The current block span that is being visited.
curr_block_span: Span,
/// The current statement that is being visited.
curr_stmt: Cow<'stmt, hir::Stmt<'tcx>>,
}

impl<'others, 'stmt, 'tcx> AuxParams<'others, 'stmt, 'tcx> {
fn new(apas: &'others mut FxIndexMap<hir::HirId, AuxParamsAttr>, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self {
fn new(apas: &'others mut FxIndexMap<HirId, AuxParamsAttr>, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self {
Self {
apas,
curr_block_hir_id: hir::HirId::INVALID,
curr_block_hir_id: HirId::INVALID,
curr_block_span: DUMMY_SP,
curr_stmt: Cow::Borrowed(curr_stmt),
}
Expand All @@ -389,7 +389,7 @@ struct AuxParamsAttr {
has_expensive_expr_after_last_attr: bool,

/// The identifier of the block that involves the first `#[has_significant_drop]`.
first_block_hir_id: hir::HirId,
first_block_hir_id: HirId,
/// The span of the block that involves the first `#[has_significant_drop]`.
first_block_span: Span,
/// The binding or variable that references the initial construction of the type marked with
Expand All @@ -414,7 +414,7 @@ impl Default for AuxParamsAttr {
Self {
counter: 0,
has_expensive_expr_after_last_attr: false,
first_block_hir_id: hir::HirId::INVALID,
first_block_hir_id: HirId::INVALID,
first_bind_ident: Ident::empty(),
first_block_span: DUMMY_SP,
first_method_span: DUMMY_SP,
Expand All @@ -428,7 +428,7 @@ impl Default for AuxParamsAttr {

fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> {
hir::Stmt {
hir_id: hir::HirId::INVALID,
hir_id: HirId::INVALID,
kind: hir::StmtKind::Expr(expr),
span: DUMMY_SP,
}
Expand Down

0 comments on commit 0aea3ed

Please sign in to comment.