@@ -3,7 +3,7 @@ use rustc_hir::{HirId, ItemId, ItemKind, Mod};
33use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
44use rustc_middle:: lint:: in_external_macro;
55use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
6- use rustc_span:: sym;
6+ use rustc_span:: { sym, Span } ;
77
88declare_clippy_lint ! {
99 /// ### What it does
@@ -43,15 +43,18 @@ declare_lint_pass!(ItemsAfterTestModule => [ITEMS_AFTER_TEST_MODULE]);
4343impl LateLintPass < ' _ > for ItemsAfterTestModule {
4444 fn check_mod ( & mut self , cx : & LateContext < ' _ > , _: & Mod < ' _ > , _: HirId ) {
4545 let mut was_test_mod_visited = false ;
46+ let mut test_mod_span: Option < Span > = None ;
4647
4748 let hir = cx. tcx . hir ( ) ;
4849 let items = hir. items ( ) . collect :: < Vec < ItemId > > ( ) ;
4950
50- for itid in items. iter ( ) {
51+ for itid in & items {
5152 let item = hir. item ( * itid) ;
5253
5354 if_chain ! {
5455 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;
5558 if !matches!( item. kind, ItemKind :: Mod ( _) ) ;
5659 if !is_in_cfg_test( cx. tcx, itid. hir_id( ) ) ; // The item isn't in the testing module itself
5760
@@ -69,6 +72,7 @@ impl LateLintPass<'_> for ItemsAfterTestModule {
6972 if mitem. has_name( sym:: test) ;
7073 then {
7174 was_test_mod_visited = true ;
75+ test_mod_span = Some ( item. span) ;
7276 }
7377 }
7478 }
0 commit comments