@@ -3,7 +3,7 @@ use rustc_hir::{HirId, ItemId, ItemKind, Mod};
3
3
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
4
4
use rustc_middle:: lint:: in_external_macro;
5
5
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
6
- use rustc_span:: sym;
6
+ use rustc_span:: { sym, Span } ;
7
7
8
8
declare_clippy_lint ! {
9
9
/// ### What it does
@@ -43,15 +43,18 @@ declare_lint_pass!(ItemsAfterTestModule => [ITEMS_AFTER_TEST_MODULE]);
43
43
impl LateLintPass < ' _ > for ItemsAfterTestModule {
44
44
fn check_mod ( & mut self , cx : & LateContext < ' _ > , _: & Mod < ' _ > , _: HirId ) {
45
45
let mut was_test_mod_visited = false ;
46
+ let mut test_mod_span: Option < Span > = None ;
46
47
47
48
let hir = cx. tcx . hir ( ) ;
48
49
let items = hir. items ( ) . collect :: < Vec < ItemId > > ( ) ;
49
50
50
- for itid in items. iter ( ) {
51
+ for itid in & items {
51
52
let item = hir. item ( * itid) ;
52
53
53
54
if_chain ! {
54
55
if was_test_mod_visited;
56
+ if cx. sess( ) . source_map( ) . lookup_char_pos( item. span. lo( ) ) . file. name_hash
57
+ == cx. sess( ) . source_map( ) . lookup_char_pos( test_mod_span. unwrap( ) . lo( ) ) . file. name_hash;
55
58
if !matches!( item. kind, ItemKind :: Mod ( _) ) ;
56
59
if !is_in_cfg_test( cx. tcx, itid. hir_id( ) ) ; // The item isn't in the testing module itself
57
60
@@ -69,6 +72,7 @@ impl LateLintPass<'_> for ItemsAfterTestModule {
69
72
if mitem. has_name( sym:: test) ;
70
73
then {
71
74
was_test_mod_visited = true ;
75
+ test_mod_span = Some ( item. span) ;
72
76
}
73
77
}
74
78
}
0 commit comments