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 } ;
4
3
use rustc_lint:: { LateContext , LateLintPass } ;
5
- use rustc_session:: { declare_tool_lint , impl_lint_pass } ;
4
+ use rustc_session:: { declare_lint_pass , declare_tool_lint } ;
6
5
use rustc_span:: { def_id:: LocalDefId , Span } ;
7
6
8
7
declare_clippy_lint ! {
@@ -43,35 +42,9 @@ declare_clippy_lint! {
43
42
"The test function `my_cool_test` is outside the testing module `tests`."
44
43
}
45
44
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 ] ) ;
57
46
58
47
impl 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
-
75
48
fn check_fn (
76
49
& mut self ,
77
50
cx : & LateContext < ' _ > ,
@@ -83,7 +56,6 @@ impl LateLintPass<'_> for TestsOutsideTestModule {
83
56
) {
84
57
if_chain ! {
85
58
if !matches!( kind, FnKind :: Closure ) ;
86
- if self . test_mod_exists;
87
59
if is_in_test_function( cx. tcx, body. id( ) . hir_id) ;
88
60
if !is_in_cfg_test( cx. tcx, body. id( ) . hir_id) ;
89
61
then {
0 commit comments