11//! This module resolves `mod foo;` declaration to file.
2+ use arrayvec:: ArrayVec ;
23use base_db:: { AnchoredPath , FileId } ;
34use hir_expand:: name:: Name ;
45use limit:: Limit ;
@@ -63,22 +64,21 @@ impl ModDir {
6364 file_id : HirFileId ,
6465 name : & Name ,
6566 attr_path : Option < & SmolStr > ,
66- ) -> Result < ( FileId , bool , ModDir ) , String > {
67+ ) -> Result < ( FileId , bool , ModDir ) , Box < [ String ] > > {
6768 let orig_file_id = file_id. original_file ( db. upcast ( ) ) ;
6869
69- let mut candidate_files = Vec :: new ( ) ;
70+ let mut candidate_files = ArrayVec :: < _ , 2 > :: new ( ) ;
7071 match attr_path {
7172 Some ( attr_path) => {
7273 candidate_files. push ( self . dir_path . join_attr ( attr_path, self . root_non_dir_owner ) )
7374 }
75+ None if file_id. is_include_macro ( db. upcast ( ) ) => {
76+ candidate_files. push ( format ! ( "{}.rs" , name) ) ;
77+ candidate_files. push ( format ! ( "{}/mod.rs" , name) ) ;
78+ }
7479 None => {
75- if file_id. is_include_macro ( db. upcast ( ) ) {
76- candidate_files. push ( format ! ( "{}.rs" , name) ) ;
77- candidate_files. push ( format ! ( "{}/mod.rs" , name) ) ;
78- } else {
79- candidate_files. push ( format ! ( "{}{}.rs" , self . dir_path. 0 , name) ) ;
80- candidate_files. push ( format ! ( "{}{}/mod.rs" , self . dir_path. 0 , name) ) ;
81- }
80+ candidate_files. push ( format ! ( "{}{}.rs" , self . dir_path. 0 , name) ) ;
81+ candidate_files. push ( format ! ( "{}{}/mod.rs" , self . dir_path. 0 , name) ) ;
8282 }
8383 } ;
8484
@@ -97,7 +97,7 @@ impl ModDir {
9797 }
9898 }
9999 }
100- Err ( candidate_files. remove ( 0 ) )
100+ Err ( candidate_files. into_iter ( ) . collect ( ) )
101101 }
102102}
103103
0 commit comments