@@ -29,7 +29,6 @@ use syntax::attr::AttrMetaMethods;
29
29
use syntax:: codemap:: Span ;
30
30
use syntax:: util:: lev_distance:: find_best_match_for_name;
31
31
32
- use std:: mem:: replace;
33
32
use std:: cell:: { Cell , RefCell } ;
34
33
35
34
/// Contains data for specific types of import directives.
@@ -41,7 +40,7 @@ pub enum ImportDirectiveSubclass {
41
40
type_determined : Cell < bool > ,
42
41
value_determined : Cell < bool > ,
43
42
} ,
44
- GlobImport ,
43
+ GlobImport { is_prelude : bool } ,
45
44
}
46
45
47
46
impl ImportDirectiveSubclass {
@@ -64,7 +63,6 @@ pub struct ImportDirective<'a> {
64
63
subclass : ImportDirectiveSubclass ,
65
64
span : Span ,
66
65
vis : ty:: Visibility , // see note in ImportResolutionPerNamespace about how to use this
67
- is_prelude : bool ,
68
66
}
69
67
70
68
impl < ' a > ImportDirective < ' a > {
@@ -84,7 +82,7 @@ impl<'a> ImportDirective<'a> {
84
82
}
85
83
86
84
pub fn is_glob ( & self ) -> bool {
87
- match self . subclass { ImportDirectiveSubclass :: GlobImport => true , _ => false }
85
+ match self . subclass { ImportDirectiveSubclass :: GlobImport { .. } => true , _ => false }
88
86
}
89
87
}
90
88
@@ -191,7 +189,7 @@ impl<'a> NameResolution<'a> {
191
189
} ;
192
190
let name = match directive. subclass {
193
191
SingleImport { source, .. } => source,
194
- GlobImport => unreachable ! ( ) ,
192
+ GlobImport { .. } => unreachable ! ( ) ,
195
193
} ;
196
194
match target_module. resolve_name ( name, ns, false ) {
197
195
Failed ( _) => { }
@@ -282,16 +280,14 @@ impl<'a> ::ModuleS<'a> {
282
280
subclass : ImportDirectiveSubclass ,
283
281
span : Span ,
284
282
id : NodeId ,
285
- vis : ty:: Visibility ,
286
- is_prelude : bool ) {
283
+ vis : ty:: Visibility ) {
287
284
let directive = self . arenas . alloc_import_directive ( ImportDirective {
288
285
module_path : module_path,
289
286
target_module : Cell :: new ( None ) ,
290
287
subclass : subclass,
291
288
span : span,
292
289
id : id,
293
290
vis : vis,
294
- is_prelude : is_prelude,
295
291
} ) ;
296
292
297
293
self . unresolved_imports . borrow_mut ( ) . push ( directive) ;
@@ -304,8 +300,8 @@ impl<'a> ::ModuleS<'a> {
304
300
}
305
301
// We don't add prelude imports to the globs since they only affect lexical scopes,
306
302
// which are not relevant to import resolution.
307
- GlobImport if directive . is_prelude => { }
308
- GlobImport => self . globs . borrow_mut ( ) . push ( directive) ,
303
+ GlobImport { is_prelude : true } => { }
304
+ GlobImport { .. } => self . globs . borrow_mut ( ) . push ( directive) ,
309
305
}
310
306
}
311
307
@@ -374,11 +370,17 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
374
370
i,
375
371
self . resolver. unresolved_imports) ;
376
372
377
- self . resolve_imports_for_module_subtree ( self . resolver . graph_root , & mut errors) ;
373
+ // Attempt to resolve imports in all local modules.
374
+ for module in self . resolver . arenas . local_modules ( ) . iter ( ) {
375
+ self . resolver . current_module = module;
376
+ self . resolve_imports_in_current_module ( & mut errors) ;
377
+ }
378
378
379
379
if self . resolver . unresolved_imports == 0 {
380
380
debug ! ( "(resolving imports) success" ) ;
381
- self . finalize_resolutions ( self . resolver . graph_root , false ) ;
381
+ for module in self . resolver . arenas . local_modules ( ) . iter ( ) {
382
+ self . finalize_resolutions_in ( module, false ) ;
383
+ }
382
384
break ;
383
385
}
384
386
@@ -388,7 +390,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
388
390
// to avoid generating multiple errors on the same import.
389
391
// Imports that are still indeterminate at this point are actually blocked
390
392
// by errored imports, so there is no point reporting them.
391
- self . finalize_resolutions ( self . resolver . graph_root , errors. len ( ) == 0 ) ;
393
+ for module in self . resolver . arenas . local_modules ( ) . iter ( ) {
394
+ self . finalize_resolutions_in ( module, errors. len ( ) == 0 ) ;
395
+ }
392
396
for e in errors {
393
397
self . import_resolving_error ( e)
394
398
}
@@ -425,22 +429,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
425
429
ResolutionError :: UnresolvedImport ( Some ( ( & path, & e. help ) ) ) ) ;
426
430
}
427
431
428
- /// Attempts to resolve imports for the given module and all of its
429
- /// submodules.
430
- fn resolve_imports_for_module_subtree ( & mut self ,
431
- module_ : Module < ' b > ,
432
- errors : & mut Vec < ImportResolvingError < ' b > > ) {
433
- debug ! ( "(resolving imports for module subtree) resolving {}" ,
434
- module_to_string( & module_) ) ;
435
- let orig_module = replace ( & mut self . resolver . current_module , module_) ;
436
- self . resolve_imports_in_current_module ( errors) ;
437
- self . resolver . current_module = orig_module;
438
-
439
- for ( _, child_module) in module_. module_children . borrow ( ) . iter ( ) {
440
- self . resolve_imports_for_module_subtree ( child_module, errors) ;
441
- }
442
- }
443
-
444
432
/// Attempts to resolve imports for the given module only.
445
433
fn resolve_imports_in_current_module ( & mut self , errors : & mut Vec < ImportResolvingError < ' b > > ) {
446
434
let mut imports = Vec :: new ( ) ;
@@ -496,7 +484,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
496
484
let ( source, target, value_determined, type_determined) = match directive. subclass {
497
485
SingleImport { source, target, ref value_determined, ref type_determined } =>
498
486
( source, target, value_determined, type_determined) ,
499
- GlobImport => return self . resolve_glob_import ( target_module, directive) ,
487
+ GlobImport { .. } => return self . resolve_glob_import ( target_module, directive) ,
500
488
} ;
501
489
502
490
// We need to resolve both namespaces for this to succeed.
@@ -644,7 +632,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
644
632
}
645
633
self . resolver . populate_module_if_necessary ( target_module) ;
646
634
647
- if directive. is_prelude {
635
+ if let GlobImport { is_prelude : true } = directive. subclass {
648
636
* module_. prelude . borrow_mut ( ) = Some ( target_module) ;
649
637
return Success ( ( ) ) ;
650
638
}
@@ -676,9 +664,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
676
664
return Success ( ( ) ) ;
677
665
}
678
666
679
- // Miscellaneous post-processing, including recording reexports, recording shadowed traits ,
680
- // reporting conflicts, reporting the PRIVATE_IN_PUBLIC lint, and reporting unresolved imports.
681
- fn finalize_resolutions ( & mut self , module : Module < ' b > , report_unresolved_imports : bool ) {
667
+ // Miscellaneous post-processing, including recording reexports, reporting conflicts ,
668
+ // reporting the PRIVATE_IN_PUBLIC lint, and reporting unresolved imports.
669
+ fn finalize_resolutions_in ( & mut self , module : Module < ' b > , report_unresolved_imports : bool ) {
682
670
// Since import resolution is finished, globs will not define any more names.
683
671
* module. globs . borrow_mut ( ) = Vec :: new ( ) ;
684
672
@@ -726,10 +714,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
726
714
break ;
727
715
}
728
716
}
729
-
730
- for ( _, child) in module. module_children . borrow ( ) . iter ( ) {
731
- self . finalize_resolutions ( child, report_unresolved_imports) ;
732
- }
733
717
}
734
718
}
735
719
@@ -747,7 +731,7 @@ fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) ->
747
731
fn import_directive_subclass_to_string ( subclass : & ImportDirectiveSubclass ) -> String {
748
732
match * subclass {
749
733
SingleImport { source, .. } => source. to_string ( ) ,
750
- GlobImport => "*" . to_string ( ) ,
734
+ GlobImport { .. } => "*" . to_string ( ) ,
751
735
}
752
736
}
753
737
0 commit comments