1010use crate :: utils:: span_lint_and_sugg;
1111use if_chain:: if_chain;
1212use rustc:: hir:: def:: { CtorKind , Def } ;
13- use rustc:: hir:: intravisit:: { walk_path, walk_ty, NestedVisitorMap , Visitor } ;
13+ use rustc:: hir:: intravisit:: { walk_item , walk_path, walk_ty, NestedVisitorMap , Visitor } ;
1414use rustc:: hir:: * ;
1515use rustc:: lint:: { in_external_macro, LateContext , LateLintPass , LintArray , LintContext , LintPass } ;
1616use rustc:: ty;
1717use rustc:: { declare_tool_lint, lint_array} ;
1818use rustc_errors:: Applicability ;
19- use syntax:: ast:: NodeId ;
2019use syntax_pos:: symbol:: keywords:: SelfUpper ;
2120
2221/// **What it does:** Checks for unnecessary repetition of structure name when a
@@ -29,7 +28,6 @@ use syntax_pos::symbol::keywords::SelfUpper;
2928/// **Known problems:**
3029/// - False positive when using associated types (#2843)
3130/// - False positives in some situations when using generics (#3410)
32- /// - False positive when type from outer function can't be used (#3463)
3331///
3432/// **Example:**
3533/// ```rust
@@ -242,8 +240,18 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
242240 walk_path ( self , path) ;
243241 }
244242
245- fn visit_use ( & mut self , _path : & ' tcx Path , _id : NodeId , _hir_id : HirId ) {
246- // Don't check use statements
243+ fn visit_item ( & mut self , item : & ' tcx Item ) {
244+ match item. node {
245+ ItemKind :: Use ( ..)
246+ | ItemKind :: Static ( ..)
247+ | ItemKind :: Enum ( ..)
248+ | ItemKind :: Struct ( ..)
249+ | ItemKind :: Union ( ..)
250+ | ItemKind :: Impl ( ..) => {
251+ // Don't check statements that shadow `Self` or where `Self` can't be used
252+ } ,
253+ _ => walk_item ( self , item) ,
254+ }
247255 }
248256
249257 fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
0 commit comments