@@ -101,12 +101,11 @@ impl LateLintPass<'_, '_> for WildcardImports {
101101 return ;
102102 }
103103 if is_test_module_or_function ( item) {
104- self . test_modules_deep += 1 ;
104+ self . test_modules_deep = self . test_modules_deep . saturating_add ( 1 ) ;
105105 }
106106 if_chain ! {
107- if self . warn_on_all || !in_macro( item. span) ;
108107 if let ItemKind :: Use ( use_path, UseKind :: Glob ) = & item. kind;
109- if self . warn_on_all || !self . check_exceptions( use_path. segments) ;
108+ if self . warn_on_all || !self . check_exceptions( item , use_path. segments) ;
110109 let used_imports = cx. tcx. names_imported_by_glob_use( item. hir_id. owner) ;
111110 if !used_imports. is_empty( ) ; // Already handled by `unused_imports`
112111 then {
@@ -177,14 +176,16 @@ impl LateLintPass<'_, '_> for WildcardImports {
177176
178177 fn check_item_post ( & mut self , _: & LateContext < ' _ , ' _ > , item : & Item < ' _ > ) {
179178 if is_test_module_or_function ( item) {
180- self . test_modules_deep -= 1 ;
179+ self . test_modules_deep = self . test_modules_deep . saturating_sub ( 1 ) ;
181180 }
182181 }
183182}
184183
185184impl WildcardImports {
186- fn check_exceptions ( & self , segments : & [ PathSegment < ' _ > ] ) -> bool {
187- is_prelude_import ( segments) || ( is_super_only_import ( segments) && self . test_modules_deep > 0 )
185+ fn check_exceptions ( & self , item : & Item < ' _ > , segments : & [ PathSegment < ' _ > ] ) -> bool {
186+ in_macro ( item. span )
187+ || is_prelude_import ( segments)
188+ || ( is_super_only_import ( segments) && self . test_modules_deep > 0 )
188189 }
189190}
190191
0 commit comments