@@ -16,6 +16,7 @@ use {NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError};
1616use { Resolver , Segment } ;
1717use { names_to_string, module_to_string} ;
1818use { resolve_error, ResolutionError } ;
19+ use macros:: ParentScope ;
1920
2021use rustc_data_structures:: ptr_key:: PtrKey ;
2122use rustc:: ty;
@@ -88,13 +89,12 @@ pub struct ImportDirective<'a> {
8889 /// Span of the *root* use tree (see `root_id`).
8990 pub root_span : Span ,
9091
91- pub parent : Module < ' a > ,
92+ pub parent_scope : ParentScope < ' a > ,
9293 pub module_path : Vec < Segment > ,
9394 /// The resolution of `module_path`.
9495 pub imported_module : Cell < Option < ModuleOrUniformRoot < ' a > > > ,
9596 pub subclass : ImportDirectiveSubclass < ' a > ,
9697 pub vis : Cell < ty:: Visibility > ,
97- pub expansion : Mark ,
9898 pub used : Cell < bool > ,
9999
100100 /// Whether this import is a "canary" for the `uniform_paths` feature,
@@ -307,8 +307,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
307307 } ;
308308 match self . resolve_ident_in_module ( module, ident, ns, false , path_span) {
309309 Err ( Determined ) => continue ,
310- Ok ( binding)
311- if !self . is_accessible_from ( binding. vis , single_import. parent ) => continue ,
310+ Ok ( binding) if !self . is_accessible_from (
311+ binding. vis , single_import. parent_scope . module
312+ ) => continue ,
312313 Ok ( _) | Err ( Undetermined ) => return Err ( Undetermined ) ,
313314 }
314315 }
@@ -381,8 +382,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
381382
382383 match result {
383384 Err ( Determined ) => continue ,
384- Ok ( binding)
385- if !self . is_accessible_from ( binding. vis , glob_import. parent ) => continue ,
385+ Ok ( binding) if !self . is_accessible_from (
386+ binding. vis , glob_import. parent_scope . module
387+ ) => continue ,
386388 Ok ( _) | Err ( Undetermined ) => return Err ( Undetermined ) ,
387389 }
388390 }
@@ -400,11 +402,11 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
400402 root_span : Span ,
401403 root_id : NodeId ,
402404 vis : ty:: Visibility ,
403- expansion : Mark ,
405+ parent_scope : ParentScope < ' a > ,
404406 is_uniform_paths_canary : bool ) {
405- let current_module = self . current_module ;
407+ let current_module = parent_scope . module ;
406408 let directive = self . arenas . alloc_import_directive ( ImportDirective {
407- parent : current_module ,
409+ parent_scope ,
408410 module_path,
409411 imported_module : Cell :: new ( None ) ,
410412 subclass,
@@ -413,7 +415,6 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
413415 root_span,
414416 root_id,
415417 vis : Cell :: new ( vis) ,
416- expansion,
417418 used : Cell :: new ( false ) ,
418419 is_uniform_paths_canary,
419420 } ) ;
@@ -431,7 +432,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
431432 // We don't add prelude imports to the globs since they only affect lexical scopes,
432433 // which are not relevant to import resolution.
433434 GlobImport { is_prelude : true , .. } => { }
434- GlobImport { .. } => self . current_module . globs . borrow_mut ( ) . push ( directive) ,
435+ GlobImport { .. } => current_module. globs . borrow_mut ( ) . push ( directive) ,
435436 _ => unreachable ! ( ) ,
436437 }
437438 }
@@ -462,7 +463,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
462463 } ,
463464 span : directive. span ,
464465 vis,
465- expansion : directive. expansion ,
466+ expansion : directive. parent_scope . expansion ,
466467 } )
467468 }
468469
@@ -568,12 +569,12 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
568569 let scope = match ident. span . reverse_glob_adjust ( module. expansion ,
569570 directive. span . ctxt ( ) . modern ( ) ) {
570571 Some ( Some ( def) ) => self . macro_def_scope ( def) ,
571- Some ( None ) => directive. parent ,
572+ Some ( None ) => directive. parent_scope . module ,
572573 None => continue ,
573574 } ;
574575 if self . is_accessible_from ( binding. vis , scope) {
575576 let imported_binding = self . import ( binding, directive) ;
576- let _ = self . try_define ( directive. parent , ident, ns, imported_binding) ;
577+ let _ = self . try_define ( directive. parent_scope . module , ident, ns, imported_binding) ;
577578 }
578579 }
579580
@@ -587,7 +588,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
587588 let dummy_binding = self . dummy_binding ;
588589 let dummy_binding = self . import ( dummy_binding, directive) ;
589590 self . per_ns ( |this, ns| {
590- let _ = this. try_define ( directive. parent , target, ns, dummy_binding) ;
591+ let _ = this. try_define ( directive. parent_scope . module , target, ns, dummy_binding) ;
591592 } ) ;
592593 }
593594 }
@@ -856,8 +857,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
856857 Segment :: names_to_string( & directive. module_path[ ..] ) ,
857858 module_to_string( self . current_module) . unwrap_or_else( || "???" . to_string( ) ) ) ;
858859
859-
860- self . current_module = directive. parent ;
860+ self . current_module = directive. parent_scope . module ;
861861
862862 let module = if let Some ( module) = directive. imported_module . get ( ) {
863863 module
@@ -868,7 +868,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
868868 directive. vis . set ( ty:: Visibility :: Invisible ) ;
869869 let result = self . resolve_path (
870870 Some ( if directive. is_uniform_paths_canary {
871- ModuleOrUniformRoot :: Module ( directive. parent )
871+ ModuleOrUniformRoot :: Module ( directive. parent_scope . module )
872872 } else {
873873 ModuleOrUniformRoot :: UniformRoot ( keywords:: Invalid . name ( ) )
874874 } ) ,
@@ -910,7 +910,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
910910 return
911911 } ;
912912
913- let parent = directive. parent ;
913+ let parent = directive. parent_scope . module ;
914914 match result[ ns] . get ( ) {
915915 Err ( Undetermined ) => indeterminate = true ,
916916 Err ( Determined ) => {
@@ -942,12 +942,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
942942
943943 // If appropriate, returns an error to report.
944944 fn finalize_import ( & mut self , directive : & ' b ImportDirective < ' b > ) -> Option < ( Span , String ) > {
945- self . current_module = directive. parent ;
945+ self . current_module = directive. parent_scope . module ;
946946 let ImportDirective { ref module_path, span, .. } = * directive;
947947
948948 let module_result = self . resolve_path (
949949 Some ( if directive. is_uniform_paths_canary {
950- ModuleOrUniformRoot :: Module ( directive. parent )
950+ ModuleOrUniformRoot :: Module ( directive. parent_scope . module )
951951 } else {
952952 ModuleOrUniformRoot :: UniformRoot ( keywords:: Invalid . name ( ) )
953953 } ) ,
@@ -995,7 +995,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
995995 }
996996
997997 if let ModuleOrUniformRoot :: Module ( module) = module {
998- if module. def_id ( ) == directive. parent . def_id ( ) {
998+ if module. def_id ( ) == directive. parent_scope . module . def_id ( ) {
999999 // Importing a module into itself is not allowed.
10001000 return Some ( ( directive. span ,
10011001 "Cannot glob-import a module into itself." . to_string ( ) ) ) ;
@@ -1189,7 +1189,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
11891189 if let Some ( Def :: Trait ( _) ) = module. def ( ) {
11901190 self . session . span_err ( directive. span , "items in traits are not importable." ) ;
11911191 return ;
1192- } else if module. def_id ( ) == directive. parent . def_id ( ) {
1192+ } else if module. def_id ( ) == directive. parent_scope . module . def_id ( ) {
11931193 return ;
11941194 } else if let GlobImport { is_prelude : true , .. } = directive. subclass {
11951195 self . prelude = Some ( module) ;
@@ -1213,7 +1213,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
12131213 } ;
12141214 if self . is_accessible_from ( binding. pseudo_vis ( ) , scope) {
12151215 let imported_binding = self . import ( binding, directive) ;
1216- let _ = self . try_define ( directive. parent , ident, ns, imported_binding) ;
1216+ let _ = self . try_define ( directive. parent_scope . module , ident, ns, imported_binding) ;
12171217 }
12181218 }
12191219
0 commit comments