@@ -8,7 +8,7 @@ use rustc_ast::attr;
88use rustc_ast:: token:: { self , TokenKind } ;
99use rustc_errors:: { struct_span_err, PResult } ;
1010use rustc_session:: parse:: ParseSess ;
11- use rustc_span:: source_map:: { FileName , Span , DUMMY_SP } ;
11+ use rustc_span:: source_map:: { FileName , Span } ;
1212use rustc_span:: symbol:: sym;
1313
1414use std:: path:: { self , Path , PathBuf } ;
@@ -24,7 +24,7 @@ pub struct ModulePath<'a> {
2424// Public for rustfmt usage.
2525pub struct ModulePathSuccess {
2626 pub path : PathBuf ,
27- pub directory_ownership : DirectoryOwnership ,
27+ pub ownership : DirectoryOwnership ,
2828}
2929
3030impl < ' a > Parser < ' a > {
@@ -45,16 +45,13 @@ impl<'a> Parser<'a> {
4545 let ( module, mut inner_attrs) = if self . eat ( & token:: Semi ) {
4646 if in_cfg && self . recurse_into_file_modules {
4747 // This mod is in an external file. Let's go get it!
48- let ModulePathSuccess { path, directory_ownership } = submod_path (
49- self . sess ,
50- id,
51- & attrs,
52- self . directory . ownership ,
53- & self . directory . path ,
54- ) ?;
55- eval_src_mod ( self . sess , self . cfg_mods , path, directory_ownership, id) ?
48+ let dir = & self . directory ;
49+ submod_path ( self . sess , id, & attrs, dir. ownership , & dir. path )
50+ . and_then ( |r| eval_src_mod ( self . sess , self . cfg_mods , r. path , r. ownership , id) )
51+ . map_err ( |mut err| err. emit ( ) )
52+ . unwrap_or_default ( )
5653 } else {
57- ( ast :: Mod { inner : DUMMY_SP , items : Vec :: new ( ) , inline : false } , Vec :: new ( ) )
54+ Default :: default ( )
5855 }
5956 } else {
6057 let old_directory = self . directory . clone ( ) ;
@@ -162,12 +159,12 @@ pub fn push_directory(
162159fn submod_path < ' a > (
163160 sess : & ' a ParseSess ,
164161 id : ast:: Ident ,
165- outer_attrs : & [ Attribute ] ,
166- directory_ownership : DirectoryOwnership ,
162+ attrs : & [ Attribute ] ,
163+ ownership : DirectoryOwnership ,
167164 dir_path : & Path ,
168165) -> PResult < ' a , ModulePathSuccess > {
169- if let Some ( path) = submod_path_from_attr ( outer_attrs , dir_path) {
170- let directory_ownership = match path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
166+ if let Some ( path) = submod_path_from_attr ( attrs , dir_path) {
167+ let ownership = match path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
171168 // All `#[path]` files are treated as though they are a `mod.rs` file.
172169 // This means that `mod foo;` declarations inside `#[path]`-included
173170 // files are siblings,
@@ -178,16 +175,16 @@ fn submod_path<'a>(
178175 Some ( _) => DirectoryOwnership :: Owned { relative : None } ,
179176 _ => DirectoryOwnership :: UnownedViaMod ,
180177 } ;
181- return Ok ( ModulePathSuccess { directory_ownership , path } ) ;
178+ return Ok ( ModulePathSuccess { ownership , path } ) ;
182179 }
183180
184- let relative = match directory_ownership {
181+ let relative = match ownership {
185182 DirectoryOwnership :: Owned { relative } => relative,
186183 DirectoryOwnership :: UnownedViaBlock | DirectoryOwnership :: UnownedViaMod => None ,
187184 } ;
188185 let ModulePath { path_exists, name, result } =
189186 default_submod_path ( sess, id, relative, dir_path) ;
190- match directory_ownership {
187+ match ownership {
191188 DirectoryOwnership :: Owned { .. } => Ok ( result?) ,
192189 DirectoryOwnership :: UnownedViaBlock => {
193190 let _ = result. map_err ( |mut err| err. cancel ( ) ) ;
@@ -300,11 +297,11 @@ pub fn default_submod_path<'a>(
300297 let result = match ( default_exists, secondary_exists) {
301298 ( true , false ) => Ok ( ModulePathSuccess {
302299 path : default_path,
303- directory_ownership : DirectoryOwnership :: Owned { relative : Some ( id) } ,
300+ ownership : DirectoryOwnership :: Owned { relative : Some ( id) } ,
304301 } ) ,
305302 ( false , true ) => Ok ( ModulePathSuccess {
306303 path : secondary_path,
307- directory_ownership : DirectoryOwnership :: Owned { relative : None } ,
304+ ownership : DirectoryOwnership :: Owned { relative : None } ,
308305 } ) ,
309306 ( false , false ) => {
310307 let mut err = struct_span_err ! (
0 commit comments