@@ -76,15 +76,13 @@ declare_clippy_lint! {
7676#[ derive( Default ) ]
7777pub struct WildcardImports {
7878 warn_on_all : bool ,
79- is_test_module : bool ,
8079 test_modules_deep : u32 ,
8180}
8281
8382impl WildcardImports {
8483 pub fn new ( warn_on_all : bool ) -> Self {
8584 Self {
8685 warn_on_all,
87- is_test_module : false ,
8886 test_modules_deep : 0 ,
8987 }
9088 }
@@ -97,8 +95,7 @@ impl LateLintPass<'_, '_> for WildcardImports {
9795 if item. vis . node . is_pub ( ) || item. vis . node . is_pub_restricted ( ) {
9896 return ;
9997 }
100- if is_test_module ( item) {
101- self . is_test_module = true ;
98+ if is_test_module_or_function ( item) {
10299 self . test_modules_deep += 1 ;
103100 }
104101 if_chain ! {
@@ -173,9 +170,8 @@ impl LateLintPass<'_, '_> for WildcardImports {
173170 }
174171 }
175172
176- fn check_item_post ( & mut self , _: & LateContext < ' _ , ' _ > , _: & Item < ' _ > ) {
177- if self . is_test_module {
178- self . is_test_module = false ;
173+ fn check_item_post ( & mut self , _: & LateContext < ' _ , ' _ > , item : & Item < ' _ > ) {
174+ if is_test_module_or_function ( item) {
179175 self . test_modules_deep -= 1 ;
180176 }
181177 }
@@ -201,6 +197,6 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
201197 segments. len ( ) == 1 && segments[ 0 ] . ident . as_str ( ) == "super"
202198}
203199
204- fn is_test_module ( item : & Item < ' _ > ) -> bool {
205- item. ident . name . as_str ( ) . contains ( "test" )
200+ fn is_test_module_or_function ( item : & Item < ' _ > ) -> bool {
201+ matches ! ( item . kind , ItemKind :: Fn ( .. ) | ItemKind :: Mod ( .. ) ) && item. ident . name . as_str ( ) . contains ( "test" )
206202}
0 commit comments