@@ -63,6 +63,7 @@ impl ImportDirectiveSubclass {
63
63
#[ derive( Debug , Clone ) ]
64
64
pub struct ImportDirective < ' a > {
65
65
pub id : NodeId ,
66
+ parent : Module < ' a > ,
66
67
module_path : Vec < Name > ,
67
68
target_module : Cell < Option < Module < ' a > > > , // the resolution of `module_path`
68
69
subclass : ImportDirectiveSubclass ,
@@ -223,6 +224,7 @@ impl<'a> Resolver<'a> {
223
224
id : NodeId ,
224
225
vis : ty:: Visibility ) {
225
226
let directive = self . arenas . alloc_import_directive ( ImportDirective {
227
+ parent : self . current_module ,
226
228
module_path : module_path,
227
229
target_module : Cell :: new ( None ) ,
228
230
subclass : subclass,
@@ -306,9 +308,9 @@ impl<'a> Resolver<'a> {
306
308
307
309
// Define `new_binding` in `module`s glob importers.
308
310
if new_binding. is_importable ( ) && new_binding. is_pseudo_public ( ) {
309
- for & ( importer , directive) in module. glob_importers . borrow_mut ( ) . iter ( ) {
311
+ for directive in module. glob_importers . borrow_mut ( ) . iter ( ) {
310
312
let imported_binding = self . import ( new_binding, directive) ;
311
- let _ = self . try_define ( importer , name, ns, imported_binding) ;
313
+ let _ = self . try_define ( directive . parent , name, ns, imported_binding) ;
312
314
}
313
315
}
314
316
@@ -317,8 +319,6 @@ impl<'a> Resolver<'a> {
317
319
}
318
320
319
321
struct ImportResolvingError < ' a > {
320
- /// Module where the error happened
321
- source_module : Module < ' a > ,
322
322
import_directive : & ' a ImportDirective < ' a > ,
323
323
span : Span ,
324
324
help : String ,
@@ -402,9 +402,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
402
402
403
403
// Define a "dummy" resolution containing a Def::Err as a placeholder for a
404
404
// failed resolution
405
- fn import_dummy_binding ( & mut self ,
406
- source_module : Module < ' b > ,
407
- directive : & ' b ImportDirective < ' b > ) {
405
+ fn import_dummy_binding ( & mut self , directive : & ' b ImportDirective < ' b > ) {
408
406
if let SingleImport { target, .. } = directive. subclass {
409
407
let dummy_binding = self . arenas . alloc_name_binding ( NameBinding {
410
408
kind : NameBindingKind :: Def ( Def :: Err ) ,
@@ -413,8 +411,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
413
411
} ) ;
414
412
let dummy_binding = self . import ( dummy_binding, directive) ;
415
413
416
- let _ = self . try_define ( source_module , target, ValueNS , dummy_binding. clone ( ) ) ;
417
- let _ = self . try_define ( source_module , target, TypeNS , dummy_binding) ;
414
+ let _ = self . try_define ( directive . parent , target, ValueNS , dummy_binding. clone ( ) ) ;
415
+ let _ = self . try_define ( directive . parent , target, TypeNS , dummy_binding) ;
418
416
}
419
417
}
420
418
@@ -423,7 +421,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
423
421
fn import_resolving_error ( & mut self , e : ImportResolvingError < ' b > ) {
424
422
// If the error is a single failed import then create a "fake" import
425
423
// resolution for it so that later resolve stages won't complain.
426
- self . import_dummy_binding ( e. source_module , e . import_directive ) ;
424
+ self . import_dummy_binding ( e. import_directive ) ;
427
425
let path = import_path_to_string ( & e. import_directive . module_path ,
428
426
& e. import_directive . subclass ) ;
429
427
resolve_error ( self . resolver ,
@@ -445,7 +443,6 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
445
443
None => ( import_directive. span , String :: new ( ) ) ,
446
444
} ;
447
445
errors. push ( ImportResolvingError {
448
- source_module : self . current_module ,
449
446
import_directive : import_directive,
450
447
span : span,
451
448
help : help,
@@ -511,7 +508,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
511
508
. emit ( ) ;
512
509
// Do not import this illegal binding. Import a dummy binding and pretend
513
510
// everything is fine
514
- self . import_dummy_binding ( module , directive) ;
511
+ self . import_dummy_binding ( directive) ;
515
512
return Success ( ( ) ) ;
516
513
}
517
514
Success ( binding) if !self . is_accessible ( binding. vis ) => { }
@@ -635,7 +632,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
635
632
}
636
633
637
634
// Add to target_module's glob_importers
638
- target_module. glob_importers . borrow_mut ( ) . push ( ( module , directive) ) ;
635
+ target_module. glob_importers . borrow_mut ( ) . push ( directive) ;
639
636
640
637
// Ensure that `resolutions` isn't borrowed during `try_define`,
641
638
// since it might get updated via a glob cycle.
0 commit comments