@@ -101,39 +101,30 @@ impl ImportDirective {
101101}
102102
103103#[ derive( Debug ) ]
104- /// An ImportResolution records what we know about an imported name in a given namespace.
104+ /// An NameResolution records what we know about an imported name in a given namespace.
105105/// More specifically, it records the number of unresolved `use` directives that import the name,
106106/// the `use` directive importing the name in the namespace, and the `NameBinding` to which the
107107/// name in the namespace resolves (if applicable).
108108/// Different `use` directives may import the same name in different namespaces.
109- pub struct ImportResolution < ' a > {
109+ pub struct NameResolution < ' a > {
110110 // When outstanding_references reaches zero, outside modules can count on the targets being
111111 // correct. Before then, all bets are off; future `use` directives could override the name.
112112 // Since shadowing is forbidden, the only way outstanding_references > 1 in a legal program
113113 // is if the name is imported by exactly two `use` directives, one of which resolves to a
114114 // value and the other of which resolves to a type.
115115 pub outstanding_references : usize ,
116116
117- /// Whether this resolution came from a `use` or a `pub use`.
118- pub is_public : bool ,
119-
120117 /// Resolution of the name in the namespace
121118 pub binding : Option < & ' a NameBinding < ' a > > ,
122-
123- /// The source node of the `use` directive
124- pub id : NodeId ,
125119}
126120
127- impl < ' a > ImportResolution < ' a > {
128- pub fn new ( id : NodeId , is_public : bool ) -> Self {
129- ImportResolution {
130- outstanding_references : 0 ,
131- id : id,
132- binding : None ,
133- is_public : is_public,
134- }
121+ impl < ' a > Default for NameResolution < ' a > {
122+ fn default ( ) -> Self {
123+ NameResolution { outstanding_references : 0 , binding : None }
135124 }
125+ }
136126
127+ impl < ' a > NameResolution < ' a > {
137128 pub fn shadowable ( & self ) -> Shadowable {
138129 match self . binding {
139130 Some ( binding) if binding. defined_with ( DefModifiers :: PRELUDE ) =>
@@ -216,8 +207,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
216207 debug ! ( "(resolving import error) adding import resolution for `{}`" ,
217208 target) ;
218209
219- ImportResolution :: new ( e. import_directive . id ,
220- e. import_directive . is_public )
210+ NameResolution :: default ( )
221211 } ) ;
222212
223213 if resolution. binding . is_none ( ) {
@@ -402,13 +392,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
402392
403393 // The name is an import which has been fully resolved, so we just follow it.
404394 Some ( resolution) if resolution. outstanding_references == 0 => {
405- // Import resolutions must be declared with "pub" in order to be exported.
406- if !resolution. is_public {
407- return Failed ( None ) ;
408- }
409-
410395 if let Some ( binding) = resolution. binding {
411- self . resolver . record_import_use ( name, ns, & resolution) ;
396+ // Import resolutions must be declared with "pub" in order to be exported.
397+ if !binding. is_public ( ) {
398+ return Failed ( None ) ;
399+ }
400+
401+ self . resolver . record_import_use ( name, ns, binding) ;
412402 Success ( binding)
413403 } else {
414404 Failed ( None )
@@ -549,10 +539,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
549539
550540 import_resolution. binding =
551541 Some ( self . resolver . new_name_binding ( directive. import ( name_binding) ) ) ;
552- import_resolution. id = directive. id ;
553- import_resolution. is_public = directive. is_public ;
554542
555- self . add_export ( module_, target, & import_resolution) ;
543+ self . add_export ( module_, target, import_resolution. binding . unwrap ( ) ) ;
556544 }
557545 Failed ( _) => {
558546 // Continue.
@@ -644,7 +632,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
644632 lp : LastPrivate )
645633 -> ResolveResult < ( ) > {
646634 let id = import_directive. id ;
647- let is_public = import_directive. is_public ;
648635
649636 // This function works in a highly imperative manner; it eagerly adds
650637 // everything it can to the list of import resolutions of the module
@@ -679,19 +666,17 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
679666 let mut import_resolutions = module_. import_resolutions . borrow_mut ( ) ;
680667 let mut dest_import_resolution =
681668 import_resolutions. entry ( ( name, ns) )
682- . or_insert_with ( || ImportResolution :: new ( id , is_public ) ) ;
669+ . or_insert_with ( || NameResolution :: default ( ) ) ;
683670
684671 match target_import_resolution. binding {
685- Some ( binding) if target_import_resolution . is_public => {
672+ Some ( binding) if binding . is_public ( ) => {
686673 self . check_for_conflicting_import ( & dest_import_resolution,
687674 import_directive. span ,
688675 name,
689676 ns) ;
690- dest_import_resolution. id = id;
691- dest_import_resolution. is_public = is_public;
692677 dest_import_resolution. binding =
693678 Some ( self . resolver . new_name_binding ( import_directive. import ( binding) ) ) ;
694- self . add_export ( module_, name, & dest_import_resolution) ;
679+ self . add_export ( module_, name, dest_import_resolution. binding . unwrap ( ) ) ;
695680 }
696681 _ => { }
697682 }
@@ -728,12 +713,11 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
728713 import_directive : & ImportDirective ,
729714 ( name, ns) : ( Name , Namespace ) ,
730715 name_binding : & ' b NameBinding < ' b > ) {
731- let id = import_directive. id ;
732716 let is_public = import_directive. is_public ;
733717
734718 let mut import_resolutions = module_. import_resolutions . borrow_mut ( ) ;
735719 let dest_import_resolution = import_resolutions. entry ( ( name, ns) ) . or_insert_with ( || {
736- ImportResolution :: new ( id , is_public )
720+ NameResolution :: default ( )
737721 } ) ;
738722
739723 debug ! ( "(resolving glob import) writing resolution `{}` in `{}` to `{}`" ,
@@ -767,9 +751,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
767751 } else {
768752 dest_import_resolution. binding =
769753 Some ( self . resolver . new_name_binding ( import_directive. import ( name_binding) ) ) ;
770- dest_import_resolution. id = id;
771- dest_import_resolution. is_public = is_public;
772- self . add_export ( module_, name, & dest_import_resolution) ;
754+ self . add_export ( module_, name, dest_import_resolution. binding . unwrap ( ) ) ;
773755 }
774756 }
775757
@@ -779,13 +761,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
779761 ( name, ns) ) ;
780762 }
781763
782- fn add_export ( & mut self , module : Module < ' b > , name : Name , resolution : & ImportResolution < ' b > ) {
783- if !resolution . is_public { return }
764+ fn add_export ( & mut self , module : Module < ' b > , name : Name , binding : & NameBinding < ' b > ) {
765+ if !binding . is_public ( ) { return }
784766 let node_id = match module. def_id ( ) {
785767 Some ( def_id) => self . resolver . ast_map . as_local_node_id ( def_id) . unwrap ( ) ,
786768 None => return ,
787769 } ;
788- let export = match resolution . binding . as_ref ( ) . unwrap ( ) . def ( ) {
770+ let export = match binding. def ( ) {
789771 Some ( def) => Export { name : name, def_id : def. def_id ( ) } ,
790772 None => return ,
791773 } ;
@@ -794,7 +776,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
794776
795777 /// Checks that imported names and items don't have the same name.
796778 fn check_for_conflicting_import ( & mut self ,
797- import_resolution : & ImportResolution ,
779+ import_resolution : & NameResolution ,
798780 import_span : Span ,
799781 name : Name ,
800782 namespace : Namespace ) {
@@ -815,8 +797,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
815797 }
816798 ValueNS => "value" ,
817799 } ;
818- let use_id = import_resolution. id ;
819- let item = self . resolver . ast_map . expect_item ( use_id) ;
820800 let mut err = struct_span_err ! ( self . resolver. session,
821801 import_span,
822802 E0252 ,
@@ -825,7 +805,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
825805 ns_word,
826806 name) ;
827807 span_note ! ( & mut err,
828- item . span,
808+ binding . span. unwrap ( ) ,
829809 "previous import of `{}` here" ,
830810 name) ;
831811 err. emit ( ) ;
@@ -848,7 +828,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
848828 /// Checks that imported names and items don't have the same name.
849829 fn check_for_conflicts_between_imports_and_items ( & mut self ,
850830 module : Module < ' b > ,
851- import : & ImportResolution < ' b > ,
831+ import : & NameResolution < ' b > ,
852832 import_span : Span ,
853833 ( name, ns) : ( Name , Namespace ) ) {
854834 // Check for item conflicts.
0 commit comments