@@ -3996,37 +3996,50 @@ impl Parser {
3996
3996
let prefix = prefix. dir_path ( ) ;
3997
3997
let mod_path_stack = & * self . mod_path_stack ;
3998
3998
let mod_path = Path ( "." ) . push_many ( * mod_path_stack) ;
3999
+ let dir_path = prefix. push_many ( mod_path. components ) ;
3999
4000
let file_path = match :: attr:: first_attr_value_str_by_name (
4000
4001
outer_attrs, "path" ) {
4001
4002
Some ( d) => {
4002
4003
let path = Path ( d) ;
4003
4004
if !path. is_absolute {
4004
- mod_path . push ( d)
4005
+ dir_path . push ( d)
4005
4006
} else {
4006
4007
path
4007
4008
}
4008
4009
}
4009
- None => mod_path. push ( token:: interner_get ( id. name ) + ".rs" ) // default
4010
+ None => {
4011
+ let mod_name = token:: interner_get ( id. name ) . to_owned ( ) ;
4012
+ let default_path_str = mod_name + ".rs" ;
4013
+ let secondary_path_str = mod_name + "/mod.rs" ;
4014
+ let default_path = dir_path. push ( default_path_str) ;
4015
+ let secondary_path = dir_path. push ( secondary_path_str) ;
4016
+ let default_exists = default_path. exists ( ) ;
4017
+ let secondary_exists = secondary_path. exists ( ) ;
4018
+ match ( default_exists, secondary_exists) {
4019
+ ( true , false ) => default_path,
4020
+ ( false , true ) => secondary_path,
4021
+ ( false , false ) => {
4022
+ self . span_fatal ( id_sp, fmt ! ( "file not found for module `%s`" , mod_name) ) ;
4023
+ }
4024
+ ( true , true ) => {
4025
+ self . span_fatal ( id_sp,
4026
+ fmt ! ( "file for module `%s` found at both %s and %s" ,
4027
+ mod_name, default_path_str, secondary_path_str) ) ;
4028
+ }
4029
+ }
4030
+ }
4010
4031
} ;
4011
4032
4012
- self . eval_src_mod_from_path ( prefix,
4013
- file_path,
4033
+ self . eval_src_mod_from_path ( file_path,
4014
4034
outer_attrs. to_owned ( ) ,
4015
4035
id_sp)
4016
4036
}
4017
4037
4018
4038
fn eval_src_mod_from_path( & self ,
4019
- prefix : Path ,
4020
4039
path : Path ,
4021
4040
outer_attrs : ~[ ast:: Attribute ] ,
4022
4041
id_sp : span ) -> ( ast:: item_ , ~[ ast:: Attribute ] ) {
4023
-
4024
- let full_path = if path. is_absolute {
4025
- path
4026
- } else {
4027
- prefix. push_many ( path. components )
4028
- } ;
4029
- let full_path = full_path. normalize ( ) ;
4042
+ let full_path = path. normalize ( ) ;
4030
4043
4031
4044
let maybe_i = do self . sess . included_mod_stack . iter ( ) . position |p| { * p == full_path } ;
4032
4045
match maybe_i {
0 commit comments