11use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_sugg} ;
2- use rustc_ast:: { ptr:: P , Crate , Item , ItemKind , MacroDef , ModKind , UseTreeKind , VisibilityKind } ;
2+ use rustc_ast:: { ptr:: P , Crate , Item , ItemKind , MacroDef , ModKind , UseTreeKind } ;
33use rustc_errors:: Applicability ;
44use rustc_lint:: { EarlyContext , EarlyLintPass , LintContext } ;
55use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -76,14 +76,13 @@ fn check_mod(cx: &EarlyContext<'_>, items: &[P<Item>]) {
7676 ) ;
7777 }
7878
79- for single_use in & single_use_usages {
80- if !imports_reused_with_self. contains ( & single_use. 0 ) {
81- let can_suggest = single_use. 2 ;
79+ for ( name, span, can_suggest) in single_use_usages {
80+ if !imports_reused_with_self. contains ( & name) {
8281 if can_suggest {
8382 span_lint_and_sugg (
8483 cx,
8584 SINGLE_COMPONENT_PATH_IMPORTS ,
86- single_use . 1 ,
85+ span ,
8786 "this import is redundant" ,
8887 "remove it entirely" ,
8988 String :: new ( ) ,
@@ -93,7 +92,7 @@ fn check_mod(cx: &EarlyContext<'_>, items: &[P<Item>]) {
9392 span_lint_and_help (
9493 cx,
9594 SINGLE_COMPONENT_PATH_IMPORTS ,
96- single_use . 1 ,
95+ span ,
9796 "this import is redundant" ,
9897 None ,
9998 "remove this import" ,
@@ -124,14 +123,11 @@ fn track_uses(
124123 ItemKind :: Use ( use_tree) => {
125124 let segments = & use_tree. prefix . segments ;
126125
127- let should_report =
128- |name : & Symbol | !macros. contains ( name) || matches ! ( item. vis. kind, VisibilityKind :: Inherited ) ;
129-
130126 // keep track of `use some_module;` usages
131127 if segments. len ( ) == 1 {
132128 if let UseTreeKind :: Simple ( None , _, _) = use_tree. kind {
133129 let name = segments[ 0 ] . ident . name ;
134- if should_report ( & name) {
130+ if !macros . contains ( & name) {
135131 single_use_usages. push ( ( name, item. span , true ) ) ;
136132 }
137133 }
@@ -146,7 +142,7 @@ fn track_uses(
146142 if segments. len ( ) == 1 {
147143 if let UseTreeKind :: Simple ( None , _, _) = tree. 0 . kind {
148144 let name = segments[ 0 ] . ident . name ;
149- if should_report ( & name) {
145+ if !macros . contains ( & name) {
150146 single_use_usages. push ( ( name, tree. 0 . span , false ) ) ;
151147 }
152148 }
0 commit comments