From 5ade9ff44ebd466d5658a6666990c84a73dcec86 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 13 Nov 2018 06:15:33 +0200 Subject: [PATCH] Fix `use_self` false positive on `use` statements --- clippy_lints/src/use_self.rs | 5 +++++ tests/ui/use_self.rs | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index db393616ff2..ad4ced995ba 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -16,6 +16,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use crate::rustc::ty; use crate::rustc::{declare_tool_lint, lint_array}; use crate::syntax_pos::symbol::keywords::SelfType; +use crate::syntax::ast::NodeId; /// **What it does:** Checks for unnecessary repetition of structure name when a /// replacement with `Self` is applicable. @@ -234,6 +235,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { walk_path(self, path); } + fn visit_use(&mut self, _path: &'tcx Path, _id: NodeId, _hir_id: HirId) { + // Don't check use statements + } + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { NestedVisitorMap::All(&self.cx.tcx.hir) } diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 4c1ec2ad2b9..60dc2d54d05 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -225,7 +225,7 @@ mod issue3410 { struct A; struct B; - trait Trait: Sized { + trait Trait { fn a(v: T); } @@ -233,3 +233,14 @@ mod issue3410 { fn a(_: Vec) {} } } + +mod issue3425 { + enum Enum { + A, + } + impl Enum { + fn a () { + use self::Enum::*; + } + } +}