@@ -29,7 +29,6 @@ use syntax::attr::AttrMetaMethods;
2929use syntax:: codemap:: Span ;
3030use syntax:: util:: lev_distance:: find_best_match_for_name;
3131
32- use std:: mem:: replace;
3332use std:: cell:: { Cell , RefCell } ;
3433
3534/// Contains data for specific types of import directives.
@@ -41,7 +40,7 @@ pub enum ImportDirectiveSubclass {
4140 type_determined : Cell < bool > ,
4241 value_determined : Cell < bool > ,
4342 } ,
44- GlobImport ,
43+ GlobImport { is_prelude : bool } ,
4544}
4645
4746impl ImportDirectiveSubclass {
@@ -64,7 +63,6 @@ pub struct ImportDirective<'a> {
6463 subclass : ImportDirectiveSubclass ,
6564 span : Span ,
6665 vis : ty:: Visibility , // see note in ImportResolutionPerNamespace about how to use this
67- is_prelude : bool ,
6866}
6967
7068impl < ' a > ImportDirective < ' a > {
@@ -84,7 +82,7 @@ impl<'a> ImportDirective<'a> {
8482 }
8583
8684 pub fn is_glob ( & self ) -> bool {
87- match self . subclass { ImportDirectiveSubclass :: GlobImport => true , _ => false }
85+ match self . subclass { ImportDirectiveSubclass :: GlobImport { .. } => true , _ => false }
8886 }
8987}
9088
@@ -191,7 +189,7 @@ impl<'a> NameResolution<'a> {
191189 } ;
192190 let name = match directive. subclass {
193191 SingleImport { source, .. } => source,
194- GlobImport => unreachable ! ( ) ,
192+ GlobImport { .. } => unreachable ! ( ) ,
195193 } ;
196194 match target_module. resolve_name ( name, ns, false ) {
197195 Failed ( _) => { }
@@ -282,16 +280,14 @@ impl<'a> ::ModuleS<'a> {
282280 subclass : ImportDirectiveSubclass ,
283281 span : Span ,
284282 id : NodeId ,
285- vis : ty:: Visibility ,
286- is_prelude : bool ) {
283+ vis : ty:: Visibility ) {
287284 let directive = self . arenas . alloc_import_directive ( ImportDirective {
288285 module_path : module_path,
289286 target_module : Cell :: new ( None ) ,
290287 subclass : subclass,
291288 span : span,
292289 id : id,
293290 vis : vis,
294- is_prelude : is_prelude,
295291 } ) ;
296292
297293 self . unresolved_imports . borrow_mut ( ) . push ( directive) ;
@@ -304,8 +300,8 @@ impl<'a> ::ModuleS<'a> {
304300 }
305301 // We don't add prelude imports to the globs since they only affect lexical scopes,
306302 // 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) ,
309305 }
310306 }
311307
@@ -374,11 +370,17 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
374370 i,
375371 self . resolver. unresolved_imports) ;
376372
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+ }
378378
379379 if self . resolver . unresolved_imports == 0 {
380380 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+ }
382384 break ;
383385 }
384386
@@ -388,7 +390,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
388390 // to avoid generating multiple errors on the same import.
389391 // Imports that are still indeterminate at this point are actually blocked
390392 // 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+ }
392396 for e in errors {
393397 self . import_resolving_error ( e)
394398 }
@@ -425,22 +429,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
425429 ResolutionError :: UnresolvedImport ( Some ( ( & path, & e. help ) ) ) ) ;
426430 }
427431
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-
444432 /// Attempts to resolve imports for the given module only.
445433 fn resolve_imports_in_current_module ( & mut self , errors : & mut Vec < ImportResolvingError < ' b > > ) {
446434 let mut imports = Vec :: new ( ) ;
@@ -496,7 +484,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
496484 let ( source, target, value_determined, type_determined) = match directive. subclass {
497485 SingleImport { source, target, ref value_determined, ref type_determined } =>
498486 ( 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) ,
500488 } ;
501489
502490 // We need to resolve both namespaces for this to succeed.
@@ -644,7 +632,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
644632 }
645633 self . resolver . populate_module_if_necessary ( target_module) ;
646634
647- if directive. is_prelude {
635+ if let GlobImport { is_prelude : true } = directive. subclass {
648636 * module_. prelude . borrow_mut ( ) = Some ( target_module) ;
649637 return Success ( ( ) ) ;
650638 }
@@ -676,9 +664,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
676664 return Success ( ( ) ) ;
677665 }
678666
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 ) {
682670 // Since import resolution is finished, globs will not define any more names.
683671 * module. globs . borrow_mut ( ) = Vec :: new ( ) ;
684672
@@ -726,10 +714,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
726714 break ;
727715 }
728716 }
729-
730- for ( _, child) in module. module_children . borrow ( ) . iter ( ) {
731- self . finalize_resolutions ( child, report_unresolved_imports) ;
732- }
733717 }
734718}
735719
@@ -747,7 +731,7 @@ fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) ->
747731fn import_directive_subclass_to_string ( subclass : & ImportDirectiveSubclass ) -> String {
748732 match * subclass {
749733 SingleImport { source, .. } => source. to_string ( ) ,
750- GlobImport => "*" . to_string ( ) ,
734+ GlobImport { .. } => "*" . to_string ( ) ,
751735 }
752736}
753737
0 commit comments