@@ -58,7 +58,7 @@ pub struct ImportDirective {
58
58
pub subclass : ImportDirectiveSubclass ,
59
59
pub span : Span ,
60
60
pub id : NodeId ,
61
- pub is_public : bool , // see note in ImportResolution about how to use this
61
+ pub is_public : bool , // see note in ImportResolutionPerNamespace about how to use this
62
62
pub shadowable : Shadowable ,
63
63
}
64
64
@@ -103,25 +103,25 @@ impl Target {
103
103
}
104
104
105
105
#[ derive( Debug ) ]
106
- /// An ImportResolution records what we know about an imported name.
106
+ /// An ImportResolutionPerNamespace records what we know about an imported name.
107
107
/// More specifically, it records the number of unresolved `use` directives that import the name,
108
108
/// and for each namespace, it records the `use` directive importing the name in the namespace
109
109
/// and the `Target` to which the name in the namespace resolves (if applicable).
110
110
/// Different `use` directives may import the same name in different namespaces.
111
- pub struct ImportResolution {
111
+ pub struct ImportResolutionPerNamespace {
112
112
// When outstanding_references reaches zero, outside modules can count on the targets being
113
113
// correct. Before then, all bets are off; future `use` directives could override the name.
114
114
// Since shadowing is forbidden, the only way outstanding_references > 1 in a legal program
115
115
// is if the name is imported by exactly two `use` directives, one of which resolves to a
116
116
// value and the other of which resolves to a type.
117
117
pub outstanding_references : usize ,
118
- pub type_ns : NsImportResolution ,
119
- pub value_ns : NsImportResolution ,
118
+ pub type_ns : ImportResolution ,
119
+ pub value_ns : ImportResolution ,
120
120
}
121
121
122
- /// Records what we know about an imported name in a namespace (see `ImportResolution `).
122
+ /// Records what we know about an imported name in a namespace (see `ImportResolutionPerNamespace `).
123
123
#[ derive( Clone , Debug ) ]
124
- pub struct NsImportResolution {
124
+ pub struct ImportResolution {
125
125
/// Whether the name in the namespace was imported with a `use` or a `pub use`.
126
126
pub is_public : bool ,
127
127
@@ -132,23 +132,23 @@ pub struct NsImportResolution {
132
132
pub id : NodeId ,
133
133
}
134
134
135
- impl :: std:: ops:: Index < Namespace > for ImportResolution {
136
- type Output = NsImportResolution ;
137
- fn index ( & self , ns : Namespace ) -> & NsImportResolution {
135
+ impl :: std:: ops:: Index < Namespace > for ImportResolutionPerNamespace {
136
+ type Output = ImportResolution ;
137
+ fn index ( & self , ns : Namespace ) -> & ImportResolution {
138
138
match ns { TypeNS => & self . type_ns , ValueNS => & self . value_ns }
139
139
}
140
140
}
141
141
142
- impl :: std:: ops:: IndexMut < Namespace > for ImportResolution {
143
- fn index_mut ( & mut self , ns : Namespace ) -> & mut NsImportResolution {
142
+ impl :: std:: ops:: IndexMut < Namespace > for ImportResolutionPerNamespace {
143
+ fn index_mut ( & mut self , ns : Namespace ) -> & mut ImportResolution {
144
144
match ns { TypeNS => & mut self . type_ns , ValueNS => & mut self . value_ns }
145
145
}
146
146
}
147
147
148
- impl ImportResolution {
149
- pub fn new ( id : NodeId , is_public : bool ) -> ImportResolution {
150
- let resolution = NsImportResolution { id : id, is_public : is_public, target : None } ;
151
- ImportResolution {
148
+ impl ImportResolutionPerNamespace {
149
+ pub fn new ( id : NodeId , is_public : bool ) -> Self {
150
+ let resolution = ImportResolution { id : id, is_public : is_public, target : None } ;
151
+ ImportResolutionPerNamespace {
152
152
outstanding_references : 0 , type_ns : resolution. clone ( ) , value_ns : resolution,
153
153
}
154
154
}
@@ -504,7 +504,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
504
504
Some ( import_resolution) if import_resolution. outstanding_references == 0 => {
505
505
506
506
fn get_binding ( this : & mut Resolver ,
507
- import_resolution : & ImportResolution ,
507
+ import_resolution : & ImportResolutionPerNamespace ,
508
508
namespace : Namespace ,
509
509
source : Name )
510
510
-> NamespaceResult {
@@ -644,7 +644,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
644
644
directive. span ,
645
645
target) ;
646
646
647
- import_resolution[ namespace] = NsImportResolution {
647
+ import_resolution[ namespace] = ImportResolution {
648
648
target : Some ( Target :: new ( target_module. clone ( ) ,
649
649
name_binding. clone ( ) ,
650
650
directive. shadowable ) ) ,
@@ -777,7 +777,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
777
777
// Here we merge two import resolutions.
778
778
let mut import_resolutions = module_. import_resolutions . borrow_mut ( ) ;
779
779
let mut dest_import_resolution = import_resolutions. entry ( * name) . or_insert_with ( || {
780
- ImportResolution :: new ( id, is_public)
780
+ ImportResolutionPerNamespace :: new ( id, is_public)
781
781
} ) ;
782
782
783
783
for & ns in [ TypeNS , ValueNS ] . iter ( ) {
@@ -787,7 +787,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
787
787
import_directive. span ,
788
788
* name,
789
789
ns) ;
790
- dest_import_resolution[ ns] = NsImportResolution {
790
+ dest_import_resolution[ ns] = ImportResolution {
791
791
id : id, is_public : is_public, target : Some ( target. clone ( ) )
792
792
} ;
793
793
}
@@ -832,10 +832,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
832
832
let is_public = import_directive. is_public ;
833
833
834
834
let mut import_resolutions = module_. import_resolutions . borrow_mut ( ) ;
835
- let dest_import_resolution = import_resolutions. entry ( name)
836
- . or_insert_with ( || {
837
- ImportResolution :: new ( id, is_public)
838
- } ) ;
835
+ let dest_import_resolution = import_resolutions. entry ( name) . or_insert_with ( || {
836
+ ImportResolutionPerNamespace :: new ( id, is_public)
837
+ } ) ;
839
838
840
839
debug ! ( "(resolving glob import) writing resolution `{}` in `{}` to `{}`" ,
841
840
name,
@@ -864,7 +863,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
864
863
"{}" ,
865
864
msg) ;
866
865
} else {
867
- dest_import_resolution[ namespace] = NsImportResolution {
866
+ dest_import_resolution[ namespace] = ImportResolution {
868
867
target : Some ( Target :: new ( containing_module. clone ( ) ,
869
868
name_bindings[ namespace] . clone ( ) ,
870
869
import_directive. shadowable ) ) ,
@@ -886,7 +885,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
886
885
887
886
/// Checks that imported names and items don't have the same name.
888
887
fn check_for_conflicting_import ( & mut self ,
889
- import_resolution : & ImportResolution ,
888
+ import_resolution : & ImportResolutionPerNamespace ,
890
889
import_span : Span ,
891
890
name : Name ,
892
891
namespace : Namespace ) {
@@ -939,14 +938,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
939
938
/// Checks that imported names and items don't have the same name.
940
939
fn check_for_conflicts_between_imports_and_items ( & mut self ,
941
940
module : & Module ,
942
- import_resolution : & ImportResolution ,
941
+ import : & ImportResolutionPerNamespace ,
943
942
import_span : Span ,
944
943
name : Name ) {
945
944
// First, check for conflicts between imports and `extern crate`s.
946
945
if module. external_module_children
947
946
. borrow ( )
948
947
. contains_key ( & name) {
949
- match import_resolution . type_ns . target {
948
+ match import . type_ns . target {
950
949
Some ( ref target) if target. shadowable != Shadowable :: Always => {
951
950
let msg = format ! ( "import `{0}` conflicts with imported crate in this module \
952
951
(maybe you meant `use {0}::*`?)",
@@ -967,7 +966,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
967
966
Some ( ref name_bindings) => ( * name_bindings) . clone ( ) ,
968
967
} ;
969
968
970
- match import_resolution . value_ns . target {
969
+ match import . value_ns . target {
971
970
Some ( ref target) if target. shadowable != Shadowable :: Always => {
972
971
if let Some ( ref value) = * name_bindings. value_ns . borrow ( ) {
973
972
span_err ! ( self . resolver. session,
@@ -983,7 +982,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
983
982
Some ( _) | None => { }
984
983
}
985
984
986
- match import_resolution . type_ns . target {
985
+ match import . type_ns . target {
987
986
Some ( ref target) if target. shadowable != Shadowable :: Always => {
988
987
if let Some ( ref ty) = * name_bindings. type_ns . borrow ( ) {
989
988
let ( what, note) = match ty. module ( ) {
0 commit comments