@@ -57,9 +57,11 @@ use tokenstream::{self, Delimited, ThinTokenStream, TokenTree, TokenStream};
57
57
use symbol:: { Symbol , keywords} ;
58
58
use util:: ThinVec ;
59
59
60
+ use std:: cmp;
60
61
use std:: collections:: HashSet ;
61
- use std:: { cmp , mem, slice } ;
62
+ use std:: mem;
62
63
use std:: path:: { self , Path , PathBuf } ;
64
+ use std:: slice;
63
65
64
66
bitflags ! {
65
67
flags Restrictions : u8 {
@@ -5363,24 +5365,25 @@ impl<'a> Parser<'a> {
5363
5365
}
5364
5366
let mut err = self . diagnostic ( ) . struct_span_err ( id_sp,
5365
5367
"cannot declare a new module at this location" ) ;
5366
- let this_module = match self . directory . path . file_name ( ) {
5367
- Some ( file_name) => file_name. to_str ( ) . unwrap ( ) . to_owned ( ) ,
5368
- None => self . root_module_name . as_ref ( ) . unwrap ( ) . clone ( ) ,
5369
- } ;
5370
- err. span_note ( id_sp,
5371
- & format ! ( "maybe move this module `{0}` to its own directory \
5372
- via `{0}{1}mod.rs`",
5373
- this_module,
5374
- path:: MAIN_SEPARATOR ) ) ;
5368
+ if id_sp != syntax_pos:: DUMMY_SP {
5369
+ let src_path = PathBuf :: from ( self . sess . codemap ( ) . span_to_filename ( id_sp) ) ;
5370
+ if let Some ( stem) = src_path. file_stem ( ) {
5371
+ let mut dest_path = src_path. clone ( ) ;
5372
+ dest_path. set_file_name ( stem) ;
5373
+ dest_path. push ( "mod.rs" ) ;
5374
+ err. span_note ( id_sp,
5375
+ & format ! ( "maybe move this module `{}` to its own \
5376
+ directory via `{}`", src_path. to_string_lossy( ) ,
5377
+ dest_path. to_string_lossy( ) ) ) ;
5378
+ }
5379
+ }
5375
5380
if paths. path_exists {
5376
5381
err. span_note ( id_sp,
5377
5382
& format ! ( "... or maybe `use` the module `{}` instead \
5378
5383
of possibly redeclaring it",
5379
5384
paths. name) ) ;
5380
- Err ( err)
5381
- } else {
5382
- Err ( err)
5383
5385
}
5386
+ Err ( err)
5384
5387
} else {
5385
5388
paths. result . map_err ( |err| self . span_fatal_err ( id_sp, err) )
5386
5389
}
0 commit comments