@@ -471,28 +471,19 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
471471 }
472472 }
473473
474- let value_def_and_priv = {
475- module_. decrement_outstanding_references_for ( target, ValueNS ) ;
476-
477- // Record what this import resolves to for later uses in documentation,
478- // this may resolve to either a value or a type, but for documentation
479- // purposes it's good enough to just favor one over the other.
480- value_result. success ( ) . map ( |binding| {
481- let def = binding. def ( ) . unwrap ( ) ;
482- let last_private = if binding. is_public ( ) { lp } else { DependsOn ( def. def_id ( ) ) } ;
483- ( def, last_private)
484- } )
485- } ;
486-
487- let type_def_and_priv = {
488- module_. decrement_outstanding_references_for ( target, TypeNS ) ;
489-
490- type_result. success ( ) . map ( |binding| {
491- let def = binding. def ( ) . unwrap ( ) ;
492- let last_private = if binding. is_public ( ) { lp } else { DependsOn ( def. def_id ( ) ) } ;
493- ( def, last_private)
494- } )
474+ // Record what this import resolves to for later uses in documentation,
475+ // this may resolve to either a value or a type, but for documentation
476+ // purposes it's good enough to just favor one over the other.
477+ module_. decrement_outstanding_references_for ( target, ValueNS ) ;
478+ module_. decrement_outstanding_references_for ( target, TypeNS ) ;
479+
480+ let def_and_priv = |binding : & NameBinding | {
481+ let def = binding. def ( ) . unwrap ( ) ;
482+ let last_private = if binding. is_public ( ) { lp } else { DependsOn ( def. def_id ( ) ) } ;
483+ ( def, last_private)
495484 } ;
485+ let value_def_and_priv = value_result. success ( ) . map ( & def_and_priv) ;
486+ let type_def_and_priv = type_result. success ( ) . map ( & def_and_priv) ;
496487
497488 let import_lp = LastImport {
498489 value_priv : value_def_and_priv. map ( |( _, p) | p) ,
@@ -501,22 +492,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
501492 type_used : Used ,
502493 } ;
503494
504- if let Some ( ( def, _) ) = value_def_and_priv {
505- self . resolver . def_map . borrow_mut ( ) . insert ( directive. id ,
506- PathResolution {
507- base_def : def,
508- last_private : import_lp,
509- depth : 0 ,
510- } ) ;
511- }
512- if let Some ( ( def, _) ) = type_def_and_priv {
513- self . resolver . def_map . borrow_mut ( ) . insert ( directive. id ,
514- PathResolution {
515- base_def : def,
516- last_private : import_lp,
517- depth : 0 ,
518- } ) ;
519- }
495+ let write_path_resolution = |( def, _) | {
496+ let path_resolution =
497+ PathResolution { base_def : def, last_private : import_lp, depth : 0 } ;
498+ self . resolver . def_map . borrow_mut ( ) . insert ( directive. id , path_resolution) ;
499+ } ;
500+ value_def_and_priv. map ( & write_path_resolution) ;
501+ type_def_and_priv. map ( & write_path_resolution) ;
520502
521503 debug ! ( "(resolving single import) successfully resolved import" ) ;
522504 return Success ( ( ) ) ;
@@ -575,19 +557,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
575557 return Success ( ( ) ) ;
576558 }
577559
578- fn add_export ( & mut self , module : Module < ' b > , name : Name , binding : & NameBinding < ' b > ) {
579- if !binding. is_public ( ) { return }
580- let node_id = match module. def_id ( ) {
581- Some ( def_id) => self . resolver . ast_map . as_local_node_id ( def_id) . unwrap ( ) ,
582- None => return ,
583- } ;
584- let export = match binding. def ( ) {
585- Some ( def) => Export { name : name, def_id : def. def_id ( ) } ,
586- None => return ,
587- } ;
588- self . resolver . export_map . entry ( node_id) . or_insert ( Vec :: new ( ) ) . push ( export) ;
589- }
590-
591560 fn define ( & mut self ,
592561 parent : Module < ' b > ,
593562 name : Name ,
@@ -596,8 +565,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
596565 let binding = self . resolver . new_name_binding ( binding) ;
597566 if let Err ( old_binding) = parent. try_define_child ( name, ns, binding) {
598567 self . report_conflict ( name, ns, binding, old_binding) ;
599- } else if binding. is_public ( ) {
600- self . add_export ( parent, name, binding) ;
568+ } else if binding. is_public ( ) { // Add to the export map
569+ if let ( Some ( parent_def_id) , Some ( def) ) = ( parent. def_id ( ) , binding. def ( ) ) {
570+ let parent_node_id = self . resolver . ast_map . as_local_node_id ( parent_def_id) . unwrap ( ) ;
571+ let export = Export { name : name, def_id : def. def_id ( ) } ;
572+ self . resolver . export_map . entry ( parent_node_id) . or_insert ( Vec :: new ( ) ) . push ( export) ;
573+ }
601574 }
602575 }
603576
0 commit comments