1
1
use 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 } ;
3
3
use rustc_errors:: Applicability ;
4
4
use rustc_lint:: { EarlyContext , EarlyLintPass , LintContext } ;
5
5
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -76,14 +76,13 @@ fn check_mod(cx: &EarlyContext<'_>, items: &[P<Item>]) {
76
76
) ;
77
77
}
78
78
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) {
82
81
if can_suggest {
83
82
span_lint_and_sugg (
84
83
cx,
85
84
SINGLE_COMPONENT_PATH_IMPORTS ,
86
- single_use . 1 ,
85
+ span ,
87
86
"this import is redundant" ,
88
87
"remove it entirely" ,
89
88
String :: new ( ) ,
@@ -93,7 +92,7 @@ fn check_mod(cx: &EarlyContext<'_>, items: &[P<Item>]) {
93
92
span_lint_and_help (
94
93
cx,
95
94
SINGLE_COMPONENT_PATH_IMPORTS ,
96
- single_use . 1 ,
95
+ span ,
97
96
"this import is redundant" ,
98
97
None ,
99
98
"remove this import" ,
@@ -124,14 +123,11 @@ fn track_uses(
124
123
ItemKind :: Use ( use_tree) => {
125
124
let segments = & use_tree. prefix . segments ;
126
125
127
- let should_report =
128
- |name : & Symbol | !macros. contains ( name) || matches ! ( item. vis. kind, VisibilityKind :: Inherited ) ;
129
-
130
126
// keep track of `use some_module;` usages
131
127
if segments. len ( ) == 1 {
132
128
if let UseTreeKind :: Simple ( None , _, _) = use_tree. kind {
133
129
let name = segments[ 0 ] . ident . name ;
134
- if should_report ( & name) {
130
+ if !macros . contains ( & name) {
135
131
single_use_usages. push ( ( name, item. span , true ) ) ;
136
132
}
137
133
}
@@ -146,7 +142,7 @@ fn track_uses(
146
142
if segments. len ( ) == 1 {
147
143
if let UseTreeKind :: Simple ( None , _, _) = tree. 0 . kind {
148
144
let name = segments[ 0 ] . ident . name ;
149
- if should_report ( & name) {
145
+ if !macros . contains ( & name) {
150
146
single_use_usages. push ( ( name, tree. 0 . span , false ) ) ;
151
147
}
152
148
}
0 commit comments