@@ -8,7 +8,7 @@ use rustc_ast::attr;
8
8
use rustc_ast:: token:: { self , TokenKind } ;
9
9
use rustc_errors:: { struct_span_err, PResult } ;
10
10
use rustc_session:: parse:: ParseSess ;
11
- use rustc_span:: source_map:: { FileName , Span , DUMMY_SP } ;
11
+ use rustc_span:: source_map:: { FileName , Span } ;
12
12
use rustc_span:: symbol:: sym;
13
13
14
14
use std:: path:: { self , Path , PathBuf } ;
@@ -24,7 +24,7 @@ pub struct ModulePath<'a> {
24
24
// Public for rustfmt usage.
25
25
pub struct ModulePathSuccess {
26
26
pub path : PathBuf ,
27
- pub directory_ownership : DirectoryOwnership ,
27
+ pub ownership : DirectoryOwnership ,
28
28
}
29
29
30
30
impl < ' a > Parser < ' a > {
@@ -45,16 +45,13 @@ impl<'a> Parser<'a> {
45
45
let ( module, mut inner_attrs) = if self . eat ( & token:: Semi ) {
46
46
if in_cfg && self . recurse_into_file_modules {
47
47
// 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 ( )
56
53
} else {
57
- ( ast :: Mod { inner : DUMMY_SP , items : Vec :: new ( ) , inline : false } , Vec :: new ( ) )
54
+ Default :: default ( )
58
55
}
59
56
} else {
60
57
let old_directory = self . directory . clone ( ) ;
@@ -162,12 +159,12 @@ pub fn push_directory(
162
159
fn submod_path < ' a > (
163
160
sess : & ' a ParseSess ,
164
161
id : ast:: Ident ,
165
- outer_attrs : & [ Attribute ] ,
166
- directory_ownership : DirectoryOwnership ,
162
+ attrs : & [ Attribute ] ,
163
+ ownership : DirectoryOwnership ,
167
164
dir_path : & Path ,
168
165
) -> 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 ( ) ) {
171
168
// All `#[path]` files are treated as though they are a `mod.rs` file.
172
169
// This means that `mod foo;` declarations inside `#[path]`-included
173
170
// files are siblings,
@@ -178,16 +175,16 @@ fn submod_path<'a>(
178
175
Some ( _) => DirectoryOwnership :: Owned { relative : None } ,
179
176
_ => DirectoryOwnership :: UnownedViaMod ,
180
177
} ;
181
- return Ok ( ModulePathSuccess { directory_ownership , path } ) ;
178
+ return Ok ( ModulePathSuccess { ownership , path } ) ;
182
179
}
183
180
184
- let relative = match directory_ownership {
181
+ let relative = match ownership {
185
182
DirectoryOwnership :: Owned { relative } => relative,
186
183
DirectoryOwnership :: UnownedViaBlock | DirectoryOwnership :: UnownedViaMod => None ,
187
184
} ;
188
185
let ModulePath { path_exists, name, result } =
189
186
default_submod_path ( sess, id, relative, dir_path) ;
190
- match directory_ownership {
187
+ match ownership {
191
188
DirectoryOwnership :: Owned { .. } => Ok ( result?) ,
192
189
DirectoryOwnership :: UnownedViaBlock => {
193
190
let _ = result. map_err ( |mut err| err. cancel ( ) ) ;
@@ -300,11 +297,11 @@ pub fn default_submod_path<'a>(
300
297
let result = match ( default_exists, secondary_exists) {
301
298
( true , false ) => Ok ( ModulePathSuccess {
302
299
path : default_path,
303
- directory_ownership : DirectoryOwnership :: Owned { relative : Some ( id) } ,
300
+ ownership : DirectoryOwnership :: Owned { relative : Some ( id) } ,
304
301
} ) ,
305
302
( false , true ) => Ok ( ModulePathSuccess {
306
303
path : secondary_path,
307
- directory_ownership : DirectoryOwnership :: Owned { relative : None } ,
304
+ ownership : DirectoryOwnership :: Owned { relative : None } ,
308
305
} ) ,
309
306
( false , false ) => {
310
307
let mut err = struct_span_err ! (
0 commit comments