From 0aea3edb3864c25dd80987810653f96118770a3e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 6 Mar 2024 17:24:13 +1100 Subject: [PATCH] Avoid lots of `hir::HirId{,Map,Set}` qualifiers. Because they're a bit redundant. --- .../src/functions/not_unsafe_ptr_arg_deref.rs | 4 +-- clippy_lints/src/index_refutable_slice.rs | 13 ++++---- .../src/operators/assign_op_pattern.rs | 33 ++++++++++--------- clippy_lints/src/ptr.rs | 4 +-- .../src/significant_drop_tightening.rs | 18 +++++----- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 2d757883f26..995dd782cbb 100644 --- a/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -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 { +fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option { if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = ( &arg.pat.kind, cx.maybe_typeck_results() diff --git a/clippy_lints/src/index_refutable_slice.rs b/clippy_lints/src/index_refutable_slice.rs index 4d1f89b1d9d..6ddc8346511 100644 --- a/clippy_lints/src/index_refutable_slice.rs +++ b/clippy_lints/src/index_refutable_slice.rs @@ -7,6 +7,7 @@ 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 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { extract_msrv_attr!(LateContext); } -fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { - let mut removed_pat: FxHashSet = FxHashSet::default(); - let mut slices: FxIndexMap = FxIndexMap::default(); +fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { + let mut removed_pat: FxHashSet = FxHashSet::default(); + let mut slices: FxIndexMap = 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 @@ fn new(ident: Ident, needs_ref: bool) -> Self { fn filter_lintable_slices<'tcx>( cx: &LateContext<'tcx>, - slice_lint_info: FxIndexMap, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, scope: &'tcx hir::Expr<'tcx>, -) -> FxIndexMap { +) -> FxIndexMap { 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, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, } diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs index 2f85130fba1..435eb9048f5 100644 --- a/clippy_lints/src/operators/assign_op_pattern.rs +++ b/clippy_lints/src/operators/assign_op_pattern.rs @@ -6,6 +6,7 @@ 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 borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind } } - 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 copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} 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 borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind } } - 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, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 83b32000a9f..d6592622f0b 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -8,7 +8,7 @@ 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, diff --git a/clippy_lints/src/significant_drop_tightening.rs b/clippy_lints/src/significant_drop_tightening.rs index d3540bc8e1c..038eb92d652 100644 --- a/clippy_lints/src/significant_drop_tightening.rs +++ b/clippy_lints/src/significant_drop_tightening.rs @@ -5,7 +5,7 @@ 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 @@ #[derive(Default)] pub struct SignificantDropTightening<'tcx> { - apas: FxIndexMap, + apas: FxIndexMap, /// Auxiliary structure used to avoid having to verify the same type multiple times. seen_types: FxHashSet>, type_cache: FxHashMap, bool>, @@ -359,9 +359,9 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { /// Auxiliary parameters used on each block check of an item struct AuxParams<'others, 'stmt, 'tcx> { //// See [AuxParamsAttr]. - apas: &'others mut FxIndexMap, + apas: &'others mut FxIndexMap, /// 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, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self { + fn new(apas: &'others mut FxIndexMap, 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 @@ fn default() -> Self { 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 @@ fn default() -> Self { 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, }