@@ -16,6 +16,7 @@ use {NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError};
16
16
use { Resolver , Segment } ;
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 < Segment > ,
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
}
@@ -856,8 +857,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
856
857
Segment :: names_to_string( & directive. module_path[ ..] ) ,
857
858
module_to_string( self . current_module) . unwrap_or_else( || "???" . to_string( ) ) ) ;
858
859
859
-
860
- self . current_module = directive. parent ;
860
+ self . current_module = directive. parent_scope . module ;
861
861
862
862
let module = if let Some ( module) = directive. imported_module . get ( ) {
863
863
module
@@ -868,7 +868,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
868
868
directive. vis . set ( ty:: Visibility :: Invisible ) ;
869
869
let result = self . resolve_path (
870
870
Some ( if directive. is_uniform_paths_canary {
871
- ModuleOrUniformRoot :: Module ( directive. parent )
871
+ ModuleOrUniformRoot :: Module ( directive. parent_scope . module )
872
872
} else {
873
873
ModuleOrUniformRoot :: UniformRoot ( keywords:: Invalid . name ( ) )
874
874
} ) ,
@@ -910,7 +910,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
910
910
return
911
911
} ;
912
912
913
- let parent = directive. parent ;
913
+ let parent = directive. parent_scope . module ;
914
914
match result[ ns] . get ( ) {
915
915
Err ( Undetermined ) => indeterminate = true ,
916
916
Err ( Determined ) => {
@@ -942,12 +942,12 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
942
942
943
943
// If appropriate, returns an error to report.
944
944
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 ;
946
946
let ImportDirective { ref module_path, span, .. } = * directive;
947
947
948
948
let module_result = self . resolve_path (
949
949
Some ( if directive. is_uniform_paths_canary {
950
- ModuleOrUniformRoot :: Module ( directive. parent )
950
+ ModuleOrUniformRoot :: Module ( directive. parent_scope . module )
951
951
} else {
952
952
ModuleOrUniformRoot :: UniformRoot ( keywords:: Invalid . name ( ) )
953
953
} ) ,
@@ -995,7 +995,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
995
995
}
996
996
997
997
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 ( ) {
999
999
// Importing a module into itself is not allowed.
1000
1000
return Some ( ( directive. span ,
1001
1001
"Cannot glob-import a module into itself." . to_string ( ) ) ) ;
@@ -1189,7 +1189,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1189
1189
if let Some ( Def :: Trait ( _) ) = module. def ( ) {
1190
1190
self . session . span_err ( directive. span , "items in traits are not importable." ) ;
1191
1191
return ;
1192
- } else if module. def_id ( ) == directive. parent . def_id ( ) {
1192
+ } else if module. def_id ( ) == directive. parent_scope . module . def_id ( ) {
1193
1193
return ;
1194
1194
} else if let GlobImport { is_prelude : true , .. } = directive. subclass {
1195
1195
self . prelude = Some ( module) ;
@@ -1213,7 +1213,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1213
1213
} ;
1214
1214
if self . is_accessible_from ( binding. pseudo_vis ( ) , scope) {
1215
1215
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) ;
1217
1217
}
1218
1218
}
1219
1219
0 commit comments