@@ -7,7 +7,8 @@ use rustc_hir::{
77 def:: { DefKind , Res } ,
88 Item , ItemKind , PathSegment , UseKind ,
99} ;
10- use rustc_lint:: { LateContext , LateLintPass } ;
10+ use rustc_hir:: { HirId , Mod } ;
11+ use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
1112use rustc_middle:: ty;
1213use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
1314use rustc_span:: symbol:: kw;
@@ -102,21 +103,40 @@ declare_clippy_lint! {
102103pub struct WildcardImports {
103104 warn_on_all : bool ,
104105 test_modules_deep : u32 ,
106+ ignore : bool ,
105107}
106108
107109impl WildcardImports {
108110 pub fn new ( warn_on_all : bool ) -> Self {
109111 Self {
110112 warn_on_all,
111113 test_modules_deep : 0 ,
114+ ignore : false ,
112115 }
113116 }
114117}
115118
116119impl_lint_pass ! ( WildcardImports => [ ENUM_GLOB_USE , WILDCARD_IMPORTS ] ) ;
117120
118121impl LateLintPass < ' _ > for WildcardImports {
122+ fn check_mod ( & mut self , cx : & LateContext < ' _ > , module : & Mod < ' _ > , _: HirId ) {
123+ let filename = cx
124+ . sess ( )
125+ . source_map ( )
126+ . span_to_filename ( module. spans . inner_span )
127+ . display ( rustc_span:: FileNameDisplayPreference :: Local )
128+ . to_string ( ) ;
129+
130+ if filename. ends_with ( "test.rs" ) || filename. ends_with ( "tests.rs" ) {
131+ self . ignore = true ;
132+ }
133+ }
134+
119135 fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
136+ if self . ignore {
137+ return ;
138+ }
139+
120140 if is_test_module_or_function ( cx. tcx , item) {
121141 self . test_modules_deep = self . test_modules_deep . saturating_add ( 1 ) ;
122142 }
0 commit comments