Skip to content

Commit 4913d82

Browse files
committed
Simplify in impl check
1 parent 8827e96 commit 4913d82

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

clippy_lints/src/use_self.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::ty::same_type_and_consts;
33
use clippy_utils::{in_macro, meets_msrv, msrvs};
44
use if_chain::if_chain;
5+
use rustc_data_structures::fx::FxHashSet;
56
use rustc_errors::Applicability;
67
use rustc_hir::{
78
self as hir,
@@ -75,7 +76,7 @@ enum StackItem {
7576
Check {
7677
hir_id: HirId,
7778
impl_trait_ref_def_id: Option<LocalDefId>,
78-
types_to_skip: Vec<HirId>,
79+
types_to_skip: FxHashSet<HirId>,
7980
types_to_lint: Vec<HirId>,
8081
},
8182
NoCheck,
@@ -111,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
111112
hir_id: self_ty.hir_id,
112113
impl_trait_ref_def_id,
113114
types_to_lint: Vec::new(),
114-
types_to_skip: Vec::new(),
115+
types_to_skip: std::iter::once(self_ty.hir_id).collect(),
115116
}
116117
} else {
117118
StackItem::NoCheck
@@ -216,7 +217,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
216217

217218
fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) {
218219
if_chain! {
219-
if !in_macro(hir_ty.span) && !in_impl(cx, hir_ty);
220+
if !in_macro(hir_ty.span);
220221
if meets_msrv(self.msrv.as_ref(), &msrvs::TYPE_ALIAS_ENUM_VARIANTS);
221222
if let Some(StackItem::Check {
222223
hir_id,
@@ -358,20 +359,6 @@ fn ty_from_hir_id<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Ty<'tcx> {
358359
}
359360
}
360361

361-
fn in_impl(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> bool {
362-
let map = cx.tcx.hir();
363-
let parent = map.get_parent_node(hir_ty.hir_id);
364-
if_chain! {
365-
if let Some(Node::Item(item)) = map.find(parent);
366-
if let ItemKind::Impl { .. } = item.kind;
367-
then {
368-
true
369-
} else {
370-
false
371-
}
372-
}
373-
}
374-
375362
fn should_lint_ty(hir_ty: &hir::Ty<'_>, ty: Ty<'_>, self_ty: Ty<'_>) -> bool {
376363
if_chain! {
377364
if same_type_and_consts(ty, self_ty);

0 commit comments

Comments
 (0)