@@ -5146,20 +5146,28 @@ impl<'a> Parser<'a> {
5146
5146
}
5147
5147
5148
5148
/// Returns either a path to a module, or .
5149
- pub fn default_submod_path ( id : ast:: Ident , dir_path : & Path , codemap : & CodeMap ) -> ModulePath
5149
+ pub fn default_submod_path ( id : ast:: Ident , dir : & Directory , codemap : & CodeMap ) -> ModulePath
5150
5150
{
5151
5151
let mod_name = id. to_string ( ) ;
5152
+ let dir_path = & dir. path ;
5152
5153
let default_path_str = format ! ( "{}.rs" , mod_name) ;
5153
5154
let secondary_path_str = format ! ( "{}/mod.rs" , mod_name) ;
5154
- let default_path = dir_path. join ( & default_path_str) ;
5155
- let secondary_path = dir_path. join ( & secondary_path_str) ;
5155
+
5156
+ let ( default_path, secondary_path) = match dir. ownership {
5157
+ DirectoryOwnership :: OwnedUnder ( under_id) => {
5158
+ let under_path = dir_path. join ( under_id. to_string ( ) ) ;
5159
+ ( under_path. join ( & default_path_str) , under_path. join ( & secondary_path_str) )
5160
+ }
5161
+ _ => ( dir_path. join ( & default_path_str) , dir_path. join ( & secondary_path_str) ) ,
5162
+ } ;
5163
+
5156
5164
let default_exists = codemap. file_exists ( & default_path) ;
5157
5165
let secondary_exists = codemap. file_exists ( & secondary_path) ;
5158
5166
5159
5167
let result = match ( default_exists, secondary_exists) {
5160
5168
( true , false ) => Ok ( ModulePathSuccess {
5161
5169
path : default_path,
5162
- directory_ownership : DirectoryOwnership :: UnownedViaMod ( false ) ,
5170
+ directory_ownership : DirectoryOwnership :: OwnedUnder ( id ) ,
5163
5171
warn : false ,
5164
5172
} ) ,
5165
5173
( false , true ) => Ok ( ModulePathSuccess {
@@ -5195,17 +5203,25 @@ impl<'a> Parser<'a> {
5195
5203
outer_attrs : & [ ast:: Attribute ] ,
5196
5204
id_sp : Span ) -> PResult < ' a , ModulePathSuccess > {
5197
5205
if let Some ( path) = Parser :: submod_path_from_attr ( outer_attrs, & self . directory . path ) {
5198
- return Ok ( ModulePathSuccess {
5199
- directory_ownership : match path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
5206
+ let ownership = {
5207
+ let file_name = path. file_name ( ) . unwrap ( ) ;
5208
+ match file_name. to_str ( ) {
5200
5209
Some ( "mod.rs" ) => DirectoryOwnership :: Owned ,
5210
+ Some ( s) if s. ends_with ( ".rs" ) && s. len ( ) > 3 => {
5211
+ let directory_name = s. rsplitn ( 2 , '.' ) . skip ( 1 ) . next ( ) . unwrap ( ) ;
5212
+ DirectoryOwnership :: OwnedUnder ( Ident :: from_str ( directory_name) )
5213
+ }
5201
5214
_ => DirectoryOwnership :: UnownedViaMod ( true ) ,
5202
- } ,
5215
+ }
5216
+ } ;
5217
+ return Ok ( ModulePathSuccess {
5218
+ directory_ownership : ownership,
5203
5219
path : path,
5204
5220
warn : false ,
5205
5221
} ) ;
5206
5222
}
5207
5223
5208
- let paths = Parser :: default_submod_path ( id, & self . directory . path , self . sess . codemap ( ) ) ;
5224
+ let paths = Parser :: default_submod_path ( id, & self . directory , self . sess . codemap ( ) ) ;
5209
5225
5210
5226
if let DirectoryOwnership :: UnownedViaBlock = self . directory . ownership {
5211
5227
let msg =
0 commit comments