1- use clippy_utils:: { diagnostics:: span_lint_and_note, is_in_cfg_test, is_in_test_function, is_test_module_or_function} ;
2- use rustc_data_structures:: sync:: par_for_each_in;
3- use rustc_hir:: { intravisit:: FnKind , Body , FnDecl , HirId , ItemKind , Mod } ;
1+ use clippy_utils:: { diagnostics:: span_lint_and_note, is_in_cfg_test, is_in_test_function} ;
2+ use rustc_hir:: { intravisit:: FnKind , Body , FnDecl } ;
43use rustc_lint:: { LateContext , LateLintPass } ;
5- use rustc_session:: { declare_tool_lint , impl_lint_pass } ;
4+ use rustc_session:: { declare_lint_pass , declare_tool_lint } ;
65use rustc_span:: { def_id:: LocalDefId , Span } ;
76
87declare_clippy_lint ! {
@@ -43,35 +42,9 @@ declare_clippy_lint! {
4342 "The test function `my_cool_test` is outside the testing module `tests`."
4443}
4544
46- pub ( crate ) struct TestsOutsideTestModule {
47- pub test_mod_exists : bool ,
48- }
49-
50- impl TestsOutsideTestModule {
51- pub fn new ( ) -> Self {
52- Self { test_mod_exists : false }
53- }
54- }
55-
56- impl_lint_pass ! ( TestsOutsideTestModule => [ TESTS_OUTSIDE_TEST_MODULE ] ) ;
45+ declare_lint_pass ! ( TestsOutsideTestModule => [ TESTS_OUTSIDE_TEST_MODULE ] ) ;
5746
5847impl LateLintPass < ' _ > for TestsOutsideTestModule {
59- fn check_mod ( & mut self , cx : & LateContext < ' _ > , _: & Mod < ' _ > , _: HirId ) {
60- self . test_mod_exists = false ;
61-
62- // par_for_each_item uses Fn, while par_for_each_in uses FnMut
63- par_for_each_in ( cx. tcx . hir_crate_items ( ( ) ) . items ( ) , |itemid| {
64- let item = cx. tcx . hir ( ) . item ( itemid) ;
65- if_chain ! {
66- if matches!( item. kind, ItemKind :: Mod ( _) ) ;
67- if is_test_module_or_function( cx. tcx, item) ;
68- then {
69- self . test_mod_exists = true ;
70- }
71- }
72- } ) ;
73- }
74-
7548 fn check_fn (
7649 & mut self ,
7750 cx : & LateContext < ' _ > ,
@@ -83,7 +56,6 @@ impl LateLintPass<'_> for TestsOutsideTestModule {
8356 ) {
8457 if_chain ! {
8558 if !matches!( kind, FnKind :: Closure ) ;
86- if self . test_mod_exists;
8759 if is_in_test_function( cx. tcx, body. id( ) . hir_id) ;
8860 if !is_in_cfg_test( cx. tcx, body. id( ) . hir_id) ;
8961 then {
0 commit comments