@@ -16,6 +16,7 @@ use {NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError};
16
16
use Resolver ;
17
17
use { names_to_string, module_to_string} ;
18
18
use { resolve_error, ResolutionError } ;
19
+ use macros:: ParentScope ;
19
20
20
21
use rustc_data_structures:: ptr_key:: PtrKey ;
21
22
use rustc:: ty;
@@ -88,13 +89,12 @@ pub struct ImportDirective<'a> {
88
89
/// Span of the *root* use tree (see `root_id`).
89
90
pub root_span : Span ,
90
91
91
- pub parent : Module < ' a > ,
92
+ pub parent_scope : ParentScope < ' a > ,
92
93
pub module_path : Vec < Ident > ,
93
94
/// The resolution of `module_path`.
94
95
pub imported_module : Cell < Option < ModuleOrUniformRoot < ' a > > > ,
95
96
pub subclass : ImportDirectiveSubclass < ' a > ,
96
97
pub vis : Cell < ty:: Visibility > ,
97
- pub expansion : Mark ,
98
98
pub used : Cell < bool > ,
99
99
100
100
/// Whether this import is a "canary" for the `uniform_paths` feature,
@@ -307,8 +307,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
307
307
} ;
308
308
match self . resolve_ident_in_module ( module, ident, ns, false , path_span) {
309
309
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 ,
312
313
Ok ( _) | Err ( Undetermined ) => return Err ( Undetermined ) ,
313
314
}
314
315
}
@@ -381,8 +382,9 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
381
382
382
383
match result {
383
384
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 ,
386
388
Ok ( _) | Err ( Undetermined ) => return Err ( Undetermined ) ,
387
389
}
388
390
}
@@ -400,11 +402,11 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
400
402
root_span : Span ,
401
403
root_id : NodeId ,
402
404
vis : ty:: Visibility ,
403
- expansion : Mark ,
405
+ parent_scope : ParentScope < ' a > ,
404
406
is_uniform_paths_canary : bool ) {
405
- let current_module = self . current_module ;
407
+ let current_module = parent_scope . module ;
406
408
let directive = self . arenas . alloc_import_directive ( ImportDirective {
407
- parent : current_module ,
409
+ parent_scope ,
408
410
module_path,
409
411
imported_module : Cell :: new ( None ) ,
410
412
subclass,
@@ -413,7 +415,6 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
413
415
root_span,
414
416
root_id,
415
417
vis : Cell :: new ( vis) ,
416
- expansion,
417
418
used : Cell :: new ( false ) ,
418
419
is_uniform_paths_canary,
419
420
} ) ;
@@ -431,7 +432,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
431
432
// We don't add prelude imports to the globs since they only affect lexical scopes,
432
433
// which are not relevant to import resolution.
433
434
GlobImport { is_prelude : true , .. } => { }
434
- GlobImport { .. } => self . current_module . globs . borrow_mut ( ) . push ( directive) ,
435
+ GlobImport { .. } => current_module. globs . borrow_mut ( ) . push ( directive) ,
435
436
_ => unreachable ! ( ) ,
436
437
}
437
438
}
@@ -462,7 +463,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
462
463
} ,
463
464
span : directive. span ,
464
465
vis,
465
- expansion : directive. expansion ,
466
+ expansion : directive. parent_scope . expansion ,
466
467
} )
467
468
}
468
469
@@ -568,12 +569,12 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
568
569
let scope = match ident. span . reverse_glob_adjust ( module. expansion ,
569
570
directive. span . ctxt ( ) . modern ( ) ) {
570
571
Some ( Some ( def) ) => self . macro_def_scope ( def) ,
571
- Some ( None ) => directive. parent ,
572
+ Some ( None ) => directive. parent_scope . module ,
572
573
None => continue ,
573
574
} ;
574
575
if self . is_accessible_from ( binding. vis , scope) {
575
576
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) ;
577
578
}
578
579
}
579
580
@@ -587,7 +588,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
587
588
let dummy_binding = self . dummy_binding ;
588
589
let dummy_binding = self . import ( dummy_binding, directive) ;
589
590
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) ;
591
592
} ) ;
592
593
}
593
594
}
@@ -854,7 +855,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
854
855
names_to_string( & directive. module_path[ ..] ) ,
855
856
module_to_string( self . current_module) . unwrap_or_else( || "???" . to_string( ) ) ) ;
856
857
857
- self . current_module = directive. parent ;
858
+ self . current_module = directive. parent_scope . module ;
858
859
859
860
let module = if let Some ( module) = directive. imported_module . get ( ) {
860
861
module
@@ -865,7 +866,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
865
866
directive. vis . set ( ty:: Visibility :: Invisible ) ;
866
867
let result = self . resolve_path (
867
868
Some ( if directive. is_uniform_paths_canary {
868
- ModuleOrUniformRoot :: Module ( directive. parent )
869
+ ModuleOrUniformRoot :: Module ( directive. parent_scope . module )
869
870
} else {
870
871
ModuleOrUniformRoot :: UniformRoot ( keywords:: Invalid . name ( ) )
871
872
} ) ,
@@ -907,7 +908,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
907
908
return
908
909
} ;
909
910
910
- let parent = directive. parent ;
911
+ let parent = directive. parent_scope . module ;
911
912
match result[ ns] . get ( ) {
912
913
Err ( Undetermined ) => indeterminate = true ,
913
914
Err ( Determined ) => {
@@ -939,12 +940,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
939
940
940
941
// If appropriate, returns an error to report.
941
942
fn finalize_import ( & mut self , directive : & ' b ImportDirective < ' b > ) -> Option < ( Span , String ) > {
942
- self . current_module = directive. parent ;
943
+ self . current_module = directive. parent_scope . module ;
943
944
let ImportDirective { ref module_path, span, .. } = * directive;
944
945
945
946
let module_result = self . resolve_path (
946
947
Some ( if directive. is_uniform_paths_canary {
947
- ModuleOrUniformRoot :: Module ( directive. parent )
948
+ ModuleOrUniformRoot :: Module ( directive. parent_scope . module )
948
949
} else {
949
950
ModuleOrUniformRoot :: UniformRoot ( keywords:: Invalid . name ( ) )
950
951
} ) ,
@@ -992,7 +993,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
992
993
}
993
994
994
995
if let ModuleOrUniformRoot :: Module ( module) = module {
995
- if module. def_id ( ) == directive. parent . def_id ( ) {
996
+ if module. def_id ( ) == directive. parent_scope . module . def_id ( ) {
996
997
// Importing a module into itself is not allowed.
997
998
return Some ( ( directive. span ,
998
999
"Cannot glob-import a module into itself." . to_string ( ) ) ) ;
@@ -1186,7 +1187,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1186
1187
if let Some ( Def :: Trait ( _) ) = module. def ( ) {
1187
1188
self . session . span_err ( directive. span , "items in traits are not importable." ) ;
1188
1189
return ;
1189
- } else if module. def_id ( ) == directive. parent . def_id ( ) {
1190
+ } else if module. def_id ( ) == directive. parent_scope . module . def_id ( ) {
1190
1191
return ;
1191
1192
} else if let GlobImport { is_prelude : true , .. } = directive. subclass {
1192
1193
self . prelude = Some ( module) ;
@@ -1210,7 +1211,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1210
1211
} ;
1211
1212
if self . is_accessible_from ( binding. pseudo_vis ( ) , scope) {
1212
1213
let imported_binding = self . import ( binding, directive) ;
1213
- let _ = self . try_define ( directive. parent , ident, ns, imported_binding) ;
1214
+ let _ = self . try_define ( directive. parent_scope . module , ident, ns, imported_binding) ;
1214
1215
}
1215
1216
}
1216
1217
0 commit comments