X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Fclippy%2Fclippy_lints%2Fsrc%2Fuse_self.rs;h=d5ee717accd26461c728990ce8a69465985580fc;hb=8759f00c73641d44b3ab7a2290e3c58168d3e30f;hp=906ac10f4610b92f0c548f2445064dde896b6a87;hpb=6e9b3696d494a32d493585f96f0671123066cd58;p=rust.git diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index 906ac10f461..d5ee717accd 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -8,8 +8,9 @@ self as hir, def::{CtorOf, DefKind, Res}, def_id::LocalDefId, - intravisit::{walk_ty, NestedVisitorMap, Visitor}, - Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, QPath, TyKind, + intravisit::{walk_ty, walk_inf, NestedVisitorMap, Visitor}, + Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Path, + QPath, TyKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; @@ -87,11 +88,8 @@ enum StackItem { impl<'tcx> LateLintPass<'tcx> for UseSelf { fn check_item(&mut self, _cx: &LateContext<'_>, item: &Item<'_>) { - if !is_item_interesting(item) { - // This does two things: - // 1) Reduce needless churn on `self.stack` - // 2) Don't push `StackItem::NoCheck` when entering `ItemKind::OpaqueTy`, - // in order to lint `foo() -> impl <..>` + if matches!(item.kind, ItemKind::OpaqueTy(_)) { + // skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>` return; } // We push the self types of `impl`s on a stack here. Only the top type on the stack is @@ -119,7 +117,7 @@ fn check_item(&mut self, _cx: &LateContext<'_>, item: &Item<'_>) { } fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) { - if is_item_interesting(item) { + if !matches!(item.kind, ItemKind::OpaqueTy(_)) { self.stack.pop(); } } @@ -266,6 +264,11 @@ struct SkipTyCollector { impl<'tcx> Visitor<'tcx> for SkipTyCollector { type Map = Map<'tcx>; + fn visit_infer(&mut self, inf: &hir::InferArg) { + self.types_to_skip.push(inf.hir_id); + + walk_inf(self, inf) + } fn visit_ty(&mut self, hir_ty: &hir::Ty<'_>) { self.types_to_skip.push(hir_ty.hir_id); @@ -297,11 +300,3 @@ fn lint_path_to_variant(cx: &LateContext<'_>, path: &Path<'_>) { span_lint(cx, span); } } - -fn is_item_interesting(item: &Item<'_>) -> bool { - use rustc_hir::ItemKind::{Const, Enum, Fn, Impl, Static, Struct, Trait, Union}; - matches!( - item.kind, - Impl { .. } | Static(..) | Const(..) | Fn(..) | Enum(..) | Struct(..) | Union(..) | Trait(..) - ) -}