@@ -13,7 +13,7 @@ use crate::attr::MetaVisitor;
13
13
use crate :: config:: FileName ;
14
14
use crate :: items:: is_mod_decl;
15
15
use crate :: syntux:: parser:: {
16
- Directory , DirectoryOwnership , ModulePathSuccess , Parser , ParserError ,
16
+ Directory , DirectoryOwnership , ModError , ModulePathSuccess , Parser , ParserError ,
17
17
} ;
18
18
use crate :: syntux:: session:: ParseSess ;
19
19
use crate :: utils:: contains_skip;
@@ -61,6 +61,9 @@ impl<'a> AstLike for Module<'a> {
61
61
fn visit_attrs ( & mut self , f : impl FnOnce ( & mut Vec < ast:: Attribute > ) ) {
62
62
f ( & mut self . inner_attr )
63
63
}
64
+ fn tokens_mut ( & mut self ) -> Option < & mut Option < rustc_ast:: tokenstream:: LazyTokenStream > > {
65
+ unimplemented ! ( )
66
+ }
64
67
}
65
68
66
69
/// Maps each module to the corresponding file.
@@ -331,7 +334,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
331
334
) -> Result < Option < SubModKind < ' c , ' ast > > , ModuleResolutionError > {
332
335
let relative = match self . directory . ownership {
333
336
DirectoryOwnership :: Owned { relative } => relative,
334
- DirectoryOwnership :: UnownedViaBlock | DirectoryOwnership :: UnownedViaMod => None ,
337
+ DirectoryOwnership :: UnownedViaBlock => None ,
335
338
} ;
336
339
if let Some ( path) = Parser :: submod_path_from_attr ( attrs, & self . directory . path ) {
337
340
if self . parse_sess . is_file_parsed ( & path) {
@@ -366,31 +369,32 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
366
369
match self
367
370
. parse_sess
368
371
. default_submod_path ( mod_name, relative, & self . directory . path )
369
- . result
370
372
{
371
373
Ok ( ModulePathSuccess {
372
- path, ownership, ..
374
+ file_path,
375
+ dir_ownership,
376
+ ..
373
377
} ) => {
374
378
let outside_mods_empty = mods_outside_ast. is_empty ( ) ;
375
379
let should_insert = !mods_outside_ast
376
380
. iter ( )
377
- . any ( |( outside_path, _, _) | outside_path == & path ) ;
378
- if self . parse_sess . is_file_parsed ( & path ) {
381
+ . any ( |( outside_path, _, _) | outside_path == & file_path ) ;
382
+ if self . parse_sess . is_file_parsed ( & file_path ) {
379
383
if outside_mods_empty {
380
384
return Ok ( None ) ;
381
385
} else {
382
386
if should_insert {
383
- mods_outside_ast. push ( ( path , ownership , sub_mod. clone ( ) ) ) ;
387
+ mods_outside_ast. push ( ( file_path , dir_ownership , sub_mod. clone ( ) ) ) ;
384
388
}
385
389
return Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) ) ;
386
390
}
387
391
}
388
- match Parser :: parse_file_as_module ( self . parse_sess , & path , sub_mod. span ) {
392
+ match Parser :: parse_file_as_module ( self . parse_sess , & file_path , sub_mod. span ) {
389
393
Ok ( ( ref attrs, _, _) ) if contains_skip ( attrs) => Ok ( None ) ,
390
394
Ok ( ( attrs, items, span) ) if outside_mods_empty => {
391
395
Ok ( Some ( SubModKind :: External (
392
- path ,
393
- ownership ,
396
+ file_path ,
397
+ dir_ownership ,
394
398
Module :: new (
395
399
span,
396
400
Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
@@ -401,8 +405,8 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
401
405
}
402
406
Ok ( ( attrs, items, span) ) => {
403
407
mods_outside_ast. push ( (
404
- path . clone ( ) ,
405
- ownership ,
408
+ file_path . clone ( ) ,
409
+ dir_ownership ,
406
410
Module :: new (
407
411
span,
408
412
Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
@@ -411,39 +415,38 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
411
415
) ,
412
416
) ) ;
413
417
if should_insert {
414
- mods_outside_ast. push ( ( path , ownership , sub_mod. clone ( ) ) ) ;
418
+ mods_outside_ast. push ( ( file_path , dir_ownership , sub_mod. clone ( ) ) ) ;
415
419
}
416
420
Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) )
417
421
}
418
422
Err ( ParserError :: ParseError ) => Err ( ModuleResolutionError {
419
423
module : mod_name. to_string ( ) ,
420
- kind : ModuleResolutionErrorKind :: ParseError { file : path } ,
424
+ kind : ModuleResolutionErrorKind :: ParseError { file : file_path } ,
421
425
} ) ,
422
426
Err ( ..) if outside_mods_empty => Err ( ModuleResolutionError {
423
427
module : mod_name. to_string ( ) ,
424
- kind : ModuleResolutionErrorKind :: NotFound { file : path } ,
428
+ kind : ModuleResolutionErrorKind :: NotFound { file : file_path } ,
425
429
} ) ,
426
430
Err ( ..) => {
427
431
if should_insert {
428
- mods_outside_ast. push ( ( path , ownership , sub_mod. clone ( ) ) ) ;
432
+ mods_outside_ast. push ( ( file_path , dir_ownership , sub_mod. clone ( ) ) ) ;
429
433
}
430
434
Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) )
431
435
}
432
436
}
433
437
}
434
- Err ( mut e) if !mods_outside_ast. is_empty ( ) => {
435
- e. cancel ( ) ;
438
+ Err ( mod_err) if !mods_outside_ast. is_empty ( ) => {
439
+ if let ModError :: ParserError ( mut e) = mod_err {
440
+ e. cancel ( ) ;
441
+ }
436
442
Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) )
437
443
}
438
- Err ( mut e) => {
439
- e. cancel ( ) ;
440
- Err ( ModuleResolutionError {
441
- module : mod_name. to_string ( ) ,
442
- kind : ModuleResolutionErrorKind :: NotFound {
443
- file : self . directory . path . clone ( ) ,
444
- } ,
445
- } )
446
- }
444
+ Err ( _) => Err ( ModuleResolutionError {
445
+ module : mod_name. to_string ( ) ,
446
+ kind : ModuleResolutionErrorKind :: NotFound {
447
+ file : self . directory . path . clone ( ) ,
448
+ } ,
449
+ } ) ,
447
450
}
448
451
}
449
452
0 commit comments