Avoid lots of hir::HirId{,Map,Set} qualifiers.

Because they're a bit redundant.
This commit is contained in:
Nicholas Nethercote 2024-03-06 17:24:13 +11:00
parent c0bc812227
commit 0aea3edb38
5 changed files with 37 additions and 35 deletions

View file

@ -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;
@ -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()

View file

@ -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;
@ -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(
@ -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,
@ -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,
}

View file

@ -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;
@ -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,
@ -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,
@ -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,
@ -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,

View file

@ -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,
@ -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,

View file

@ -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;
@ -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>,
@ -359,9 +359,9 @@ 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.
@ -369,10 +369,10 @@ struct AuxParams<'others, '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),
}
@ -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
@ -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,
@ -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,
}