@@ -41,25 +41,26 @@ pub struct ModulePathSuccess {
4141crate fn parse_external_mod (
4242 sess : & ParseSess ,
4343 id : ast:: Ident ,
44+ span : Span , // The span to blame on errors.
4445 Directory { mut ownership, path } : Directory ,
4546 attrs : & mut Vec < Attribute > ,
4647 pop_mod_stack : & mut bool ,
4748) -> ( Mod , Directory ) {
4849 // We bail on the first error, but that error does not cause a fatal error... (1)
4950 let result: PResult < ' _ , _ > = try {
5051 // Extract the file path and the new ownership.
51- let mp = submod_path ( sess, id, & attrs, ownership, & path) ?;
52+ let mp = submod_path ( sess, id, span , & attrs, ownership, & path) ?;
5253 ownership = mp. ownership ;
5354
5455 // Ensure file paths are acyclic.
5556 let mut included_mod_stack = sess. included_mod_stack . borrow_mut ( ) ;
56- error_on_circular_module ( sess, id . span , & mp. path , & included_mod_stack) ?;
57+ error_on_circular_module ( sess, span, & mp. path , & included_mod_stack) ?;
5758 included_mod_stack. push ( mp. path . clone ( ) ) ;
5859 * pop_mod_stack = true ; // We have pushed, so notify caller.
5960 drop ( included_mod_stack) ;
6061
6162 // Actually parse the external file as amodule.
62- let mut p0 = new_sub_parser_from_file ( sess, & mp. path , Some ( id. to_string ( ) ) , id . span ) ;
63+ let mut p0 = new_sub_parser_from_file ( sess, & mp. path , Some ( id. to_string ( ) ) , span) ;
6364 let mut module = p0. parse_mod ( & token:: Eof ) ?;
6465 module. 0 . inline = false ;
6566 module
@@ -126,6 +127,7 @@ crate fn push_directory(
126127fn submod_path < ' a > (
127128 sess : & ' a ParseSess ,
128129 id : ast:: Ident ,
130+ span : Span ,
129131 attrs : & [ Attribute ] ,
130132 ownership : DirectoryOwnership ,
131133 dir_path : & Path ,
@@ -150,54 +152,53 @@ fn submod_path<'a>(
150152 DirectoryOwnership :: UnownedViaBlock | DirectoryOwnership :: UnownedViaMod => None ,
151153 } ;
152154 let ModulePath { path_exists, name, result } =
153- default_submod_path ( sess, id, relative, dir_path) ;
155+ default_submod_path ( sess, id, span , relative, dir_path) ;
154156 match ownership {
155157 DirectoryOwnership :: Owned { .. } => Ok ( result?) ,
156158 DirectoryOwnership :: UnownedViaBlock => {
157159 let _ = result. map_err ( |mut err| err. cancel ( ) ) ;
158- error_decl_mod_in_block ( sess, id . span , path_exists, & name)
160+ error_decl_mod_in_block ( sess, span, path_exists, & name)
159161 }
160162 DirectoryOwnership :: UnownedViaMod => {
161163 let _ = result. map_err ( |mut err| err. cancel ( ) ) ;
162- error_cannot_declare_mod_here ( sess, id . span , path_exists, & name)
164+ error_cannot_declare_mod_here ( sess, span, path_exists, & name)
163165 }
164166 }
165167}
166168
167169fn error_decl_mod_in_block < ' a , T > (
168170 sess : & ' a ParseSess ,
169- id_sp : Span ,
171+ span : Span ,
170172 path_exists : bool ,
171173 name : & str ,
172174) -> PResult < ' a , T > {
173175 let msg = "Cannot declare a non-inline module inside a block unless it has a path attribute" ;
174- let mut err = sess. span_diagnostic . struct_span_err ( id_sp , msg) ;
176+ let mut err = sess. span_diagnostic . struct_span_err ( span , msg) ;
175177 if path_exists {
176178 let msg = format ! ( "Maybe `use` the module `{}` instead of redeclaring it" , name) ;
177- err. span_note ( id_sp , & msg) ;
179+ err. span_note ( span , & msg) ;
178180 }
179181 Err ( err)
180182}
181183
182184fn error_cannot_declare_mod_here < ' a , T > (
183185 sess : & ' a ParseSess ,
184- id_sp : Span ,
186+ span : Span ,
185187 path_exists : bool ,
186188 name : & str ,
187189) -> PResult < ' a , T > {
188190 let mut err =
189- sess. span_diagnostic . struct_span_err ( id_sp , "cannot declare a new module at this location" ) ;
190- if !id_sp . is_dummy ( ) {
191- if let FileName :: Real ( src_path) = sess. source_map ( ) . span_to_filename ( id_sp ) {
191+ sess. span_diagnostic . struct_span_err ( span , "cannot declare a new module at this location" ) ;
192+ if !span . is_dummy ( ) {
193+ if let FileName :: Real ( src_path) = sess. source_map ( ) . span_to_filename ( span ) {
192194 if let Some ( stem) = src_path. file_stem ( ) {
193195 let mut dest_path = src_path. clone ( ) ;
194196 dest_path. set_file_name ( stem) ;
195197 dest_path. push ( "mod.rs" ) ;
196198 err. span_note (
197- id_sp ,
199+ span ,
198200 & format ! (
199- "maybe move this module `{}` to its own \
200- directory via `{}`",
201+ "maybe move this module `{}` to its own directory via `{}`" ,
201202 src_path. display( ) ,
202203 dest_path. display( )
203204 ) ,
@@ -207,7 +208,7 @@ fn error_cannot_declare_mod_here<'a, T>(
207208 }
208209 if path_exists {
209210 err. span_note (
210- id_sp ,
211+ span ,
211212 & format ! ( "... or maybe `use` the module `{}` instead of possibly redeclaring it" , name) ,
212213 ) ;
213214 }
@@ -237,6 +238,7 @@ pub fn submod_path_from_attr(attrs: &[Attribute], dir_path: &Path) -> Option<Pat
237238pub fn default_submod_path < ' a > (
238239 sess : & ' a ParseSess ,
239240 id : ast:: Ident ,
241+ span : Span ,
240242 relative : Option < ast:: Ident > ,
241243 dir_path : & Path ,
242244) -> ModulePath < ' a > {
@@ -273,7 +275,7 @@ pub fn default_submod_path<'a>(
273275 ( false , false ) => {
274276 let mut err = struct_span_err ! (
275277 sess. span_diagnostic,
276- id . span,
278+ span,
277279 E0583 ,
278280 "file not found for module `{}`" ,
279281 mod_name,
@@ -289,7 +291,7 @@ pub fn default_submod_path<'a>(
289291 ( true , true ) => {
290292 let mut err = struct_span_err ! (
291293 sess. span_diagnostic,
292- id . span,
294+ span,
293295 E0584 ,
294296 "file for module `{}` found at both {} and {}" ,
295297 mod_name,
0 commit comments