From 4913d82175366c1b303afce17071d070d8203874 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 16 Jun 2021 12:23:09 -0500 Subject: [PATCH] Simplify in impl check --- clippy_lints/src/use_self.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 9cac3b20ac519..fea4b6c5c91c7 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::ty::same_type_and_consts; use clippy_utils::{in_macro, meets_msrv, msrvs}; use if_chain::if_chain; +use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::{ self as hir, @@ -75,7 +76,7 @@ enum StackItem { Check { hir_id: HirId, impl_trait_ref_def_id: Option, - types_to_skip: Vec, + types_to_skip: FxHashSet, types_to_lint: Vec, }, NoCheck, @@ -111,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { hir_id: self_ty.hir_id, impl_trait_ref_def_id, types_to_lint: Vec::new(), - types_to_skip: Vec::new(), + types_to_skip: std::iter::once(self_ty.hir_id).collect(), } } else { StackItem::NoCheck @@ -216,7 +217,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) { if_chain! { - if !in_macro(hir_ty.span) && !in_impl(cx, hir_ty); + if !in_macro(hir_ty.span); if meets_msrv(self.msrv.as_ref(), &msrvs::TYPE_ALIAS_ENUM_VARIANTS); if let Some(StackItem::Check { hir_id, @@ -358,20 +359,6 @@ fn ty_from_hir_id<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Ty<'tcx> { } } -fn in_impl(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> bool { - let map = cx.tcx.hir(); - let parent = map.get_parent_node(hir_ty.hir_id); - if_chain! { - if let Some(Node::Item(item)) = map.find(parent); - if let ItemKind::Impl { .. } = item.kind; - then { - true - } else { - false - } - } -} - fn should_lint_ty(hir_ty: &hir::Ty<'_>, ty: Ty<'_>, self_ty: Ty<'_>) -> bool { if_chain! { if same_type_and_consts(ty, self_ty);