@@ -657,62 +657,58 @@ impl<'a, 'b> TestDefs<'a, 'b> {
657657 }
658658
659659 fn expect_test ( & self ) -> bool {
660- self . find_macro ( "expect_test: expect" ) || self . find_macro ( "expect_test:: expect_file")
660+ self . find_macro ( "expect_test" , & [ " expect", " expect_file"] )
661661 }
662662
663663 fn insta ( & self ) -> bool {
664- self . find_macro ( "insta:assert_snapshot" )
665- || self . find_macro ( "insta:assert_debug_snapshot" )
666- || self . find_macro ( "insta:assert_display_snapshot" )
667- || self . find_macro ( "insta:assert_json_snapshot" )
668- || self . find_macro ( "insta:assert_yaml_snapshot" )
669- || self . find_macro ( "insta:assert_ron_snapshot" )
670- || self . find_macro ( "insta:assert_toml_snapshot" )
671- || self . find_macro ( "insta:assert_csv_snapshot" )
672- || self . find_macro ( "insta:assert_compact_json_snapshot" )
673- || self . find_macro ( "insta:assert_compact_debug_snapshot" )
674- || self . find_macro ( "insta:assert_binary_snapshot" )
664+ self . find_macro (
665+ "insta" ,
666+ & [
667+ "assert_snapshot" ,
668+ "assert_debug_snapshot" ,
669+ "assert_display_snapshot" ,
670+ "assert_json_snapshot" ,
671+ "assert_yaml_snapshot" ,
672+ "assert_ron_snapshot" ,
673+ "assert_toml_snapshot" ,
674+ "assert_csv_snapshot" ,
675+ "assert_compact_json_snapshot" ,
676+ "assert_compact_debug_snapshot" ,
677+ "assert_binary_snapshot" ,
678+ ] ,
679+ )
675680 }
676681
677682 fn snapbox ( & self ) -> bool {
678- self . find_macro ( "snapbox:assert_data_eq" )
679- || self . find_macro ( "snapbox:file" )
680- || self . find_macro ( "snapbox:str" )
683+ self . find_macro ( "snapbox" , & [ "assert_data_eq" , "file" , "str" ] )
681684 }
682685
683- fn find_macro ( & self , path : & str ) -> bool {
684- let Some ( hir:: ScopeDef :: ModuleDef ( hir:: ModuleDef :: Macro ( it) ) ) = self . find_def ( path) else {
685- return false ;
686- } ;
687-
688- Definition :: Macro ( it)
689- . usages ( self . 0 )
690- . in_scope ( & SearchScope :: file_range ( self . 2 ) )
691- . at_least_one ( )
692- }
693-
694- fn find_def ( & self , path : & str ) -> Option < hir:: ScopeDef > {
686+ fn find_macro ( & self , crate_name : & str , paths : & [ & str ] ) -> bool {
695687 let db = self . 0 . db ;
696688
697- let mut path = path. split ( ':' ) ;
698- let item = path. next_back ( ) ?;
699- let krate = path. next ( ) ?;
700- let dep = self . 1 . dependencies ( db) . into_iter ( ) . find ( |dep| dep. name . eq_ident ( krate) ) ?;
701-
702- let mut module = dep. krate . root_module ( ) ;
703- for segment in path {
704- module = module. children ( db) . find_map ( |child| {
705- let name = child. name ( db) ?;
706- if name. eq_ident ( segment) {
707- Some ( child)
708- } else {
709- None
689+ let Some ( dep) =
690+ self . 1 . dependencies ( db) . into_iter ( ) . find ( |dep| dep. name . eq_ident ( crate_name) )
691+ else {
692+ return false ;
693+ } ;
694+ let module = dep. krate . root_module ( ) ;
695+ let scope = module. scope ( db, None ) ;
696+
697+ paths
698+ . iter ( )
699+ . filter_map ( |path| {
700+ let ( _, def) = scope. iter ( ) . find ( |( name, _) | name. eq_ident ( path) ) ?;
701+ match def {
702+ hir:: ScopeDef :: ModuleDef ( hir:: ModuleDef :: Macro ( it) ) => Some ( it) ,
703+ _ => None ,
710704 }
711- } ) ?;
712- }
713-
714- let ( _, def) = module. scope ( db, None ) . into_iter ( ) . find ( |( name, _) | name. eq_ident ( item) ) ?;
715- Some ( def)
705+ } )
706+ . any ( |makro| {
707+ Definition :: Macro ( * makro)
708+ . usages ( self . 0 )
709+ . in_scope ( & SearchScope :: file_range ( self . 2 ) )
710+ . at_least_one ( )
711+ } )
716712 }
717713}
718714
0 commit comments