@@ -65,7 +65,7 @@ pub struct ImportDirective<'a> {
65
65
pub id : NodeId ,
66
66
parent : Module < ' a > ,
67
67
module_path : Vec < Name > ,
68
- target_module : Cell < Option < Module < ' a > > > , // the resolution of `module_path`
68
+ imported_module : Cell < Option < Module < ' a > > > , // the resolution of `module_path`
69
69
subclass : ImportDirectiveSubclass < ' a > ,
70
70
span : Span ,
71
71
vis : Cell < ty:: Visibility > ,
@@ -192,8 +192,8 @@ impl<'a> Resolver<'a> {
192
192
// Check if the globs are determined
193
193
for directive in module. globs . borrow ( ) . iter ( ) {
194
194
if self . is_accessible ( directive. vis . get ( ) ) {
195
- if let Some ( target_module ) = directive. target_module . get ( ) {
196
- let result = self . resolve_name_in_module ( target_module , name, ns, true , None ) ;
195
+ if let Some ( module ) = directive. imported_module . get ( ) {
196
+ let result = self . resolve_name_in_module ( module , name, ns, true , None ) ;
197
197
if let Indeterminate = result {
198
198
return Indeterminate ;
199
199
}
@@ -220,15 +220,15 @@ impl<'a> Resolver<'a> {
220
220
match resolution. single_imports {
221
221
SingleImports :: AtLeastOne => return Some ( Indeterminate ) ,
222
222
SingleImports :: MaybeOne ( directive) if self . is_accessible ( directive. vis . get ( ) ) => {
223
- let target_module = match directive. target_module . get ( ) {
224
- Some ( target_module ) => target_module ,
223
+ let module = match directive. imported_module . get ( ) {
224
+ Some ( module ) => module ,
225
225
None => return Some ( Indeterminate ) ,
226
226
} ;
227
227
let name = match directive. subclass {
228
228
SingleImport { source, .. } => source,
229
229
GlobImport { .. } => unreachable ! ( ) ,
230
230
} ;
231
- match self . resolve_name_in_module ( target_module , name, ns, true , None ) {
231
+ match self . resolve_name_in_module ( module , name, ns, true , None ) {
232
232
Failed ( _) => { }
233
233
_ => return Some ( Indeterminate ) ,
234
234
}
@@ -250,7 +250,7 @@ impl<'a> Resolver<'a> {
250
250
let directive = self . arenas . alloc_import_directive ( ImportDirective {
251
251
parent : current_module,
252
252
module_path : module_path,
253
- target_module : Cell :: new ( None ) ,
253
+ imported_module : Cell :: new ( None ) ,
254
254
subclass : subclass,
255
255
span : span,
256
256
id : id,
@@ -485,10 +485,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
485
485
names_to_string( & directive. module_path) ,
486
486
module_to_string( self . current_module) ) ;
487
487
488
- let module = directive. parent ;
489
- self . set_current_module ( module) ;
488
+ self . set_current_module ( directive. parent ) ;
490
489
491
- let target_module = if let Some ( module) = directive. target_module . get ( ) {
490
+ let module = if let Some ( module) = directive. imported_module . get ( ) {
492
491
module
493
492
} else {
494
493
let vis = directive. vis . get ( ) ;
@@ -506,7 +505,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
506
505
}
507
506
} ;
508
507
509
- directive. target_module . set ( Some ( target_module ) ) ;
508
+ directive. imported_module . set ( Some ( module ) ) ;
510
509
let ( source, target, value_result, type_result) = match directive. subclass {
511
510
SingleImport { source, target, ref value_result, ref type_result } =>
512
511
( source, target, value_result, type_result) ,
@@ -520,7 +519,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
520
519
for & ( ns, result) in & [ ( ValueNS , value_result) , ( TypeNS , type_result) ] {
521
520
if let Err ( false ) = result. get ( ) {
522
521
result. set ( {
523
- match self . resolve_name_in_module ( target_module , source, ns, false , None ) {
522
+ match self . resolve_name_in_module ( module , source, ns, false , None ) {
524
523
Success ( binding) => Ok ( binding) ,
525
524
Indeterminate => Err ( false ) ,
526
525
Failed ( _) => Err ( true ) ,
@@ -533,7 +532,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
533
532
match result. get ( ) {
534
533
Err ( false ) => indeterminate = true ,
535
534
Err ( true ) => {
536
- self . update_resolution ( module , target, ns, |_, resolution| {
535
+ self . update_resolution ( directive . parent , target, ns, |_, resolution| {
537
536
resolution. single_imports . directive_failed ( )
538
537
} ) ;
539
538
}
@@ -549,10 +548,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
549
548
}
550
549
Ok ( binding) => {
551
550
let imported_binding = self . import ( binding, directive) ;
552
- let conflict = self . try_define ( module , target, ns, imported_binding) ;
551
+ let conflict = self . try_define ( directive . parent , target, ns, imported_binding) ;
553
552
if let Err ( old_binding) = conflict {
554
553
let binding = & self . import ( binding, directive) ;
555
- self . report_conflict ( module , target, ns, binding, old_binding) ;
554
+ self . report_conflict ( directive . parent , target, ns, binding, old_binding) ;
556
555
}
557
556
}
558
557
}
@@ -666,38 +665,37 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
666
665
}
667
666
668
667
fn resolve_glob_import ( & mut self , directive : & ' b ImportDirective < ' b > ) {
669
- let target_module = directive. target_module . get ( ) . unwrap ( ) ;
670
- self . populate_module_if_necessary ( target_module ) ;
668
+ let module = directive. imported_module . get ( ) . unwrap ( ) ;
669
+ self . populate_module_if_necessary ( module ) ;
671
670
672
- if let Some ( Def :: Trait ( _) ) = target_module . def {
671
+ if let Some ( Def :: Trait ( _) ) = module . def {
673
672
self . session . span_err ( directive. span , "items in traits are not importable." ) ;
674
673
}
675
674
676
- let module = directive. parent ;
677
- if target_module. def_id ( ) == module. def_id ( ) {
675
+ if module. def_id ( ) == directive. parent . def_id ( ) {
678
676
return ;
679
677
} else if let GlobImport { is_prelude : true } = directive. subclass {
680
- self . prelude = Some ( target_module ) ;
678
+ self . prelude = Some ( module ) ;
681
679
return ;
682
680
}
683
681
684
- // Add to target_module 's glob_importers
685
- target_module . glob_importers . borrow_mut ( ) . push ( directive) ;
682
+ // Add to module 's glob_importers
683
+ module . glob_importers . borrow_mut ( ) . push ( directive) ;
686
684
687
685
// Ensure that `resolutions` isn't borrowed during `try_define`,
688
686
// since it might get updated via a glob cycle.
689
- let bindings = target_module . resolutions . borrow ( ) . iter ( ) . filter_map ( |( name, resolution) | {
687
+ let bindings = module . resolutions . borrow ( ) . iter ( ) . filter_map ( |( name, resolution) | {
690
688
resolution. borrow ( ) . binding ( ) . map ( |binding| ( * name, binding) )
691
689
} ) . collect :: < Vec < _ > > ( ) ;
692
690
for ( ( name, ns) , binding) in bindings {
693
691
if binding. is_importable ( ) && binding. is_pseudo_public ( ) {
694
692
let imported_binding = self . import ( binding, directive) ;
695
- let _ = self . try_define ( module , name, ns, imported_binding) ;
693
+ let _ = self . try_define ( directive . parent , name, ns, imported_binding) ;
696
694
}
697
695
}
698
696
699
697
// Record the destination of this import
700
- if let Some ( did) = target_module . def_id ( ) {
698
+ if let Some ( did) = module . def_id ( ) {
701
699
let resolution = PathResolution :: new ( Def :: Mod ( did) ) ;
702
700
self . def_map . insert ( directive. id , resolution) ;
703
701
}
0 commit comments