@@ -275,7 +275,6 @@ impl<'a> ::ModuleS<'a> {
275
275
// Define the name or return the existing binding if there is a collision.
276
276
pub fn try_define_child ( & self , name : Name , ns : Namespace , binding : NameBinding < ' a > )
277
277
-> Result < ( ) , & ' a NameBinding < ' a > > {
278
- if self . resolutions . borrow_state ( ) != :: std:: cell:: BorrowState :: Unused { return Ok ( ( ) ) ; }
279
278
self . update_resolution ( name, ns, |resolution| {
280
279
resolution. try_define ( self . arenas . alloc_name_binding ( binding) )
281
280
} )
@@ -318,15 +317,20 @@ impl<'a> ::ModuleS<'a> {
318
317
fn update_resolution < T , F > ( & self , name : Name , ns : Namespace , update : F ) -> T
319
318
where F : FnOnce ( & mut NameResolution < ' a > ) -> T
320
319
{
321
- let mut resolution = & mut * self . resolution ( name, ns) . borrow_mut ( ) ;
322
- let was_known = resolution. binding ( ) . is_some ( ) ;
320
+ let ( new_binding, t) = {
321
+ let mut resolution = & mut * self . resolution ( name, ns) . borrow_mut ( ) ;
322
+ let was_known = resolution. binding ( ) . is_some ( ) ;
323
323
324
- let t = update ( resolution) ;
325
- if !was_known {
326
- if let Some ( binding) = resolution. binding ( ) {
327
- self . define_in_glob_importers ( name, ns, binding) ;
324
+ let t = update ( resolution) ;
325
+
326
+ if was_known { return t; }
327
+ match resolution. binding ( ) {
328
+ Some ( binding) => ( binding, t) ,
329
+ None => return t,
328
330
}
329
- }
331
+ } ;
332
+
333
+ self . define_in_glob_importers ( name, ns, new_binding) ;
330
334
t
331
335
}
332
336
@@ -646,11 +650,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
646
650
// Add to target_module's glob_importers
647
651
target_module. glob_importers . borrow_mut ( ) . push ( ( module_, directive) ) ;
648
652
649
- for ( & ( name, ns) , resolution) in target_module. resolutions . borrow ( ) . iter ( ) {
650
- if let Some ( binding) = resolution. borrow ( ) . binding ( ) {
651
- if binding. defined_with ( DefModifiers :: IMPORTABLE | DefModifiers :: PUBLIC ) {
652
- let _ = module_. try_define_child ( name, ns, directive. import ( binding, None ) ) ;
653
- }
653
+ let bindings = target_module. resolutions . borrow ( ) . iter ( ) . filter_map ( |( name, resolution) | {
654
+ resolution. borrow ( ) . binding ( ) . map ( |binding| ( * name, binding) )
655
+ } ) . collect :: < Vec < _ > > ( ) ;
656
+ for ( ( name, ns) , binding) in bindings {
657
+ if binding. defined_with ( DefModifiers :: IMPORTABLE | DefModifiers :: PUBLIC ) {
658
+ let _ = module_. try_define_child ( name, ns, directive. import ( binding, None ) ) ;
654
659
}
655
660
}
656
661
0 commit comments