@@ -13,7 +13,9 @@ use crate::config::FileName;
13
13
use crate :: formatting:: {
14
14
attr:: MetaVisitor ,
15
15
items:: is_mod_decl,
16
- syntux:: parser:: { Directory , DirectoryOwnership , ModulePathSuccess , Parser , ParserError } ,
16
+ syntux:: parser:: {
17
+ Directory , DirectoryOwnership , ModError , ModulePathSuccess , Parser , ParserError ,
18
+ } ,
17
19
syntux:: session:: ParseSess ,
18
20
utils:: contains_skip,
19
21
} ;
@@ -104,6 +106,9 @@ impl<'a> AstLike for Module<'a> {
104
106
fn visit_attrs ( & mut self , f : impl FnOnce ( & mut Vec < ast:: Attribute > ) ) {
105
107
f ( & mut self . inner_attr )
106
108
}
109
+ fn tokens_mut ( & mut self ) -> Option < & mut Option < rustc_ast:: tokenstream:: LazyTokenStream > > {
110
+ unimplemented ! ( )
111
+ }
107
112
}
108
113
109
114
/// Maps each module to the corresponding file.
@@ -371,7 +376,7 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
371
376
) -> Result < Option < SubModKind < ' ast > > , ModuleResolutionError > {
372
377
let relative = match self . directory . ownership {
373
378
DirectoryOwnership :: Owned { relative } => relative,
374
- DirectoryOwnership :: UnownedViaBlock | DirectoryOwnership :: UnownedViaMod => None ,
379
+ DirectoryOwnership :: UnownedViaBlock => None ,
375
380
} ;
376
381
if let Some ( path) =
377
382
Parser :: submod_path_from_attr ( sub_mod. outer_attrs ( ) , & self . directory . path )
@@ -412,34 +417,35 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
412
417
match self
413
418
. parse_sess
414
419
. default_submod_path ( sub_mod. ident ( ) , relative, & self . directory . path )
415
- . result
416
420
{
417
421
Ok ( ModulePathSuccess {
418
- path, ownership, ..
422
+ file_path,
423
+ dir_ownership,
424
+ ..
419
425
} ) => {
420
426
let outside_mods_empty = mods_outside_ast. is_empty ( ) ;
421
427
let should_insert = !mods_outside_ast
422
428
. iter ( )
423
- . any ( |( outside_path, _, _) | outside_path == & path ) ;
424
- if self . parse_sess . is_file_parsed ( & path ) {
429
+ . any ( |( outside_path, _, _) | outside_path == & file_path ) ;
430
+ if self . parse_sess . is_file_parsed ( & file_path ) {
425
431
if outside_mods_empty {
426
432
return Ok ( None ) ;
427
433
} else {
428
434
if should_insert {
429
- mods_outside_ast. push ( ( path , ownership , sub_mod. clone ( ) ) ) ;
435
+ mods_outside_ast. push ( ( file_path , dir_ownership , sub_mod. clone ( ) ) ) ;
430
436
}
431
437
return Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) ) ;
432
438
}
433
439
}
434
440
match Parser :: parse_file_as_module (
435
441
self . parse_sess ,
436
- & path ,
442
+ & file_path ,
437
443
sub_mod. outside_ast_mod_span ( ) ,
438
444
) {
439
445
Ok ( ( attrs, items, span) ) if outside_mods_empty => {
440
446
Ok ( Some ( SubModKind :: External (
441
- path ,
442
- ownership ,
447
+ file_path ,
448
+ dir_ownership ,
443
449
Module :: new (
444
450
span,
445
451
Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
@@ -451,8 +457,8 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
451
457
}
452
458
Ok ( ( attrs, items, span) ) => {
453
459
mods_outside_ast. push ( (
454
- path . clone ( ) ,
455
- ownership ,
460
+ file_path . clone ( ) ,
461
+ dir_ownership ,
456
462
Module :: new (
457
463
span,
458
464
Some ( Cow :: Owned ( ast:: ModKind :: Unloaded ) ) ,
@@ -462,39 +468,38 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
462
468
) ,
463
469
) ) ;
464
470
if should_insert {
465
- mods_outside_ast. push ( ( path , ownership , sub_mod. clone ( ) ) ) ;
471
+ mods_outside_ast. push ( ( file_path , dir_ownership , sub_mod. clone ( ) ) ) ;
466
472
}
467
473
Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) )
468
474
}
469
475
Err ( ParserError :: ParseError ) => Err ( ModuleResolutionError {
470
476
module : sub_mod. name ( ) ,
471
- kind : ModuleResolutionErrorKind :: ParseError { file : path } ,
477
+ kind : ModuleResolutionErrorKind :: ParseError { file : file_path } ,
472
478
} ) ,
473
479
Err ( ..) if outside_mods_empty => Err ( ModuleResolutionError {
474
480
module : sub_mod. name ( ) ,
475
- kind : ModuleResolutionErrorKind :: NotFound { file : path } ,
481
+ kind : ModuleResolutionErrorKind :: NotFound { file : file_path } ,
476
482
} ) ,
477
483
Err ( ..) => {
478
484
if should_insert {
479
- mods_outside_ast. push ( ( path , ownership , sub_mod. clone ( ) ) ) ;
485
+ mods_outside_ast. push ( ( file_path , dir_ownership , sub_mod. clone ( ) ) ) ;
480
486
}
481
487
Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) )
482
488
}
483
489
}
484
490
}
485
- Err ( mut e) if !mods_outside_ast. is_empty ( ) => {
486
- e. cancel ( ) ;
491
+ Err ( mod_err) if !mods_outside_ast. is_empty ( ) => {
492
+ if let ModError :: ParserError ( mut e) = mod_err {
493
+ e. cancel ( ) ;
494
+ }
487
495
Ok ( Some ( SubModKind :: MultiExternal ( mods_outside_ast) ) )
488
496
}
489
- Err ( mut e) => {
490
- e. cancel ( ) ;
491
- Err ( ModuleResolutionError {
492
- module : sub_mod. name ( ) ,
493
- kind : ModuleResolutionErrorKind :: NotFound {
494
- file : self . directory . path . clone ( ) ,
495
- } ,
496
- } )
497
- }
497
+ Err ( _) => Err ( ModuleResolutionError {
498
+ module : sub_mod. name ( ) ,
499
+ kind : ModuleResolutionErrorKind :: NotFound {
500
+ file : self . directory . path . clone ( ) ,
501
+ } ,
502
+ } ) ,
498
503
}
499
504
}
500
505
0 commit comments