1
1
use clippy_utils:: diagnostics:: span_lint_and_sugg;
2
- use clippy_utils:: is_test_module_or_function ;
2
+ use clippy_utils:: is_in_test ;
3
3
use clippy_utils:: source:: { snippet, snippet_with_applicability} ;
4
4
use rustc_data_structures:: fx:: FxHashSet ;
5
5
use rustc_errors:: Applicability ;
@@ -100,15 +100,13 @@ declare_clippy_lint! {
100
100
#[ derive( Default ) ]
101
101
pub struct WildcardImports {
102
102
warn_on_all : bool ,
103
- test_modules_deep : u32 ,
104
103
allowed_segments : FxHashSet < String > ,
105
104
}
106
105
107
106
impl WildcardImports {
108
107
pub fn new ( warn_on_all : bool , allowed_wildcard_imports : FxHashSet < String > ) -> Self {
109
108
Self {
110
109
warn_on_all,
111
- test_modules_deep : 0 ,
112
110
allowed_segments : allowed_wildcard_imports,
113
111
}
114
112
}
@@ -122,15 +120,12 @@ impl LateLintPass<'_> for WildcardImports {
122
120
return ;
123
121
}
124
122
125
- if is_test_module_or_function ( cx. tcx , item) {
126
- self . test_modules_deep = self . test_modules_deep . saturating_add ( 1 ) ;
127
- }
128
123
let module = cx. tcx . parent_module_from_def_id ( item. owner_id . def_id ) ;
129
124
if cx. tcx . visibility ( item. owner_id . def_id ) != ty:: Visibility :: Restricted ( module. to_def_id ( ) ) {
130
125
return ;
131
126
}
132
127
if let ItemKind :: Use ( use_path, UseKind :: Glob ) = & item. kind
133
- && ( self . warn_on_all || !self . check_exceptions ( item, use_path. segments ) )
128
+ && ( self . warn_on_all || !self . check_exceptions ( cx , item, use_path. segments ) )
134
129
&& let used_imports = cx. tcx . names_imported_by_glob_use ( item. owner_id . def_id )
135
130
&& !used_imports. is_empty ( ) // Already handled by `unused_imports`
136
131
&& !used_imports. contains ( & kw:: Underscore )
@@ -180,20 +175,14 @@ impl LateLintPass<'_> for WildcardImports {
180
175
span_lint_and_sugg ( cx, lint, span, message, "try" , sugg, applicability) ;
181
176
}
182
177
}
183
-
184
- fn check_item_post ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
185
- if is_test_module_or_function ( cx. tcx , item) {
186
- self . test_modules_deep = self . test_modules_deep . saturating_sub ( 1 ) ;
187
- }
188
- }
189
178
}
190
179
191
180
impl WildcardImports {
192
- fn check_exceptions ( & self , item : & Item < ' _ > , segments : & [ PathSegment < ' _ > ] ) -> bool {
181
+ fn check_exceptions ( & self , cx : & LateContext < ' _ > , item : & Item < ' _ > , segments : & [ PathSegment < ' _ > ] ) -> bool {
193
182
item. span . from_expansion ( )
194
183
|| is_prelude_import ( segments)
195
- || ( is_super_only_import ( segments) && self . test_modules_deep > 0 )
196
184
|| is_allowed_via_config ( segments, & self . allowed_segments )
185
+ || ( is_super_only_import ( segments) && is_in_test ( cx. tcx , item. hir_id ( ) ) )
197
186
}
198
187
}
199
188
0 commit comments