@@ -76,15 +76,13 @@ declare_clippy_lint! {
76
76
#[ derive( Default ) ]
77
77
pub struct WildcardImports {
78
78
warn_on_all : bool ,
79
- is_test_module : bool ,
80
79
test_modules_deep : u32 ,
81
80
}
82
81
83
82
impl WildcardImports {
84
83
pub fn new ( warn_on_all : bool ) -> Self {
85
84
Self {
86
85
warn_on_all,
87
- is_test_module : false ,
88
86
test_modules_deep : 0 ,
89
87
}
90
88
}
@@ -97,8 +95,7 @@ impl LateLintPass<'_, '_> for WildcardImports {
97
95
if item. vis . node . is_pub ( ) || item. vis . node . is_pub_restricted ( ) {
98
96
return ;
99
97
}
100
- if is_test_module ( item) {
101
- self . is_test_module = true ;
98
+ if is_test_module_or_function ( item) {
102
99
self . test_modules_deep += 1 ;
103
100
}
104
101
if_chain ! {
@@ -173,9 +170,8 @@ impl LateLintPass<'_, '_> for WildcardImports {
173
170
}
174
171
}
175
172
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) {
179
175
self . test_modules_deep -= 1 ;
180
176
}
181
177
}
@@ -201,6 +197,6 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
201
197
segments. len ( ) == 1 && segments[ 0 ] . ident . as_str ( ) == "super"
202
198
}
203
199
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" )
206
202
}
0 commit comments