@@ -120,8 +120,6 @@ enum SuggestionType {
120
120
}
121
121
122
122
pub enum ResolutionError < ' a > {
123
- /// error E0260: name conflicts with an extern crate
124
- NameConflictsWithExternCrate ( Name ) ,
125
123
/// error E0401: can't use type parameters from outer function
126
124
TypeParametersFromOuterFunction ,
127
125
/// error E0402: cannot use an outer type parameter in this context
@@ -228,14 +226,6 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
228
226
}
229
227
230
228
match resolution_error {
231
- ResolutionError :: NameConflictsWithExternCrate ( name) => {
232
- struct_span_err ! ( resolver. session,
233
- span,
234
- E0260 ,
235
- "the name `{}` conflicts with an external crate \
236
- that has been imported into this module",
237
- name)
238
- }
239
229
ResolutionError :: TypeParametersFromOuterFunction => {
240
230
struct_span_err ! ( resolver. session,
241
231
span,
@@ -801,14 +791,11 @@ pub struct ModuleS<'a> {
801
791
parent_link : ParentLink < ' a > ,
802
792
def : Cell < Option < Def > > ,
803
793
is_public : bool ,
794
+ is_extern_crate : bool ,
804
795
805
796
children : RefCell < HashMap < ( Name , Namespace ) , NameBinding < ' a > > > ,
806
797
imports : RefCell < Vec < ImportDirective > > ,
807
798
808
- // The external module children of this node that were declared with
809
- // `extern crate`.
810
- external_module_children : RefCell < HashMap < Name , Module < ' a > > > ,
811
-
812
799
// The anonymous children of this node. Anonymous children are pseudo-
813
800
// modules that are implicitly created around items contained within
814
801
// blocks.
@@ -854,9 +841,9 @@ impl<'a> ModuleS<'a> {
854
841
parent_link : parent_link,
855
842
def : Cell :: new ( def) ,
856
843
is_public : is_public,
844
+ is_extern_crate : false ,
857
845
children : RefCell :: new ( HashMap :: new ( ) ) ,
858
846
imports : RefCell :: new ( Vec :: new ( ) ) ,
859
- external_module_children : RefCell :: new ( HashMap :: new ( ) ) ,
860
847
anonymous_children : RefCell :: new ( NodeMap ( ) ) ,
861
848
import_resolutions : RefCell :: new ( HashMap :: new ( ) ) ,
862
849
glob_count : Cell :: new ( 0 ) ,
@@ -871,10 +858,21 @@ impl<'a> ModuleS<'a> {
871
858
self . children . borrow ( ) . get ( & ( name, ns) ) . cloned ( )
872
859
}
873
860
874
- fn try_define_child ( & self , name : Name , ns : Namespace , binding : NameBinding < ' a > ) -> bool {
861
+ // If the name is not yet defined, define the name and return None.
862
+ // Otherwise, return the existing definition.
863
+ fn try_define_child ( & self , name : Name , ns : Namespace , binding : NameBinding < ' a > )
864
+ -> Option < NameBinding < ' a > > {
875
865
match self . children . borrow_mut ( ) . entry ( ( name, ns) ) {
876
- hash_map:: Entry :: Vacant ( entry) => { entry. insert ( binding) ; true }
877
- hash_map:: Entry :: Occupied ( _) => false ,
866
+ hash_map:: Entry :: Vacant ( entry) => { entry. insert ( binding) ; None }
867
+ hash_map:: Entry :: Occupied ( entry) => { Some ( entry. get ( ) . clone ( ) ) } ,
868
+ }
869
+ }
870
+
871
+ fn for_each_local_child < F : FnMut ( Name , Namespace , & NameBinding < ' a > ) > ( & self , mut f : F ) {
872
+ for ( & ( name, ns) , name_binding) in self . children . borrow ( ) . iter ( ) {
873
+ if !name_binding. is_extern_crate ( ) {
874
+ f ( name, ns, name_binding)
875
+ }
878
876
}
879
877
}
880
878
@@ -1005,6 +1003,10 @@ impl<'a> NameBinding<'a> {
1005
1003
let def = self . def ( ) . unwrap ( ) ;
1006
1004
( def, LastMod ( if self . is_public ( ) { AllPublic } else { DependsOn ( def. def_id ( ) ) } ) )
1007
1005
}
1006
+
1007
+ fn is_extern_crate ( & self ) -> bool {
1008
+ self . module ( ) . map ( |module| module. is_extern_crate ) . unwrap_or ( false )
1009
+ }
1008
1010
}
1009
1011
1010
1012
/// Interns the names of the primitive types.
@@ -1184,6 +1186,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1184
1186
self . arenas . modules . alloc ( ModuleS :: new ( parent_link, def, external, is_public) )
1185
1187
}
1186
1188
1189
+ fn new_extern_crate_module ( & self , parent_link : ParentLink < ' a > , def : Def ) -> Module < ' a > {
1190
+ let mut module = ModuleS :: new ( parent_link, Some ( def) , false , true ) ;
1191
+ module. is_extern_crate = true ;
1192
+ self . arenas . modules . alloc ( module)
1193
+ }
1194
+
1187
1195
fn get_ribs < ' b > ( & ' b mut self , ns : Namespace ) -> & ' b mut Vec < Rib < ' a > > {
1188
1196
match ns { ValueNS => & mut self . value_ribs , TypeNS => & mut self . type_ribs }
1189
1197
}
@@ -1211,32 +1219,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1211
1219
}
1212
1220
}
1213
1221
1214
- /// Check that an external crate doesn't collide with items or other external crates.
1215
- fn check_for_conflicts_for_external_crate ( & self , module : Module < ' a > , name : Name , span : Span ) {
1216
- if module. external_module_children . borrow ( ) . contains_key ( & name) {
1217
- span_err ! ( self . session,
1218
- span,
1219
- E0259 ,
1220
- "an external crate named `{}` has already been imported into this module" ,
1221
- name) ;
1222
- }
1223
- if let Some ( name_binding) = module. get_child ( name, TypeNS ) {
1224
- resolve_error ( self ,
1225
- name_binding. span . unwrap_or ( codemap:: DUMMY_SP ) ,
1226
- ResolutionError :: NameConflictsWithExternCrate ( name) ) ;
1227
- }
1228
- }
1229
-
1230
- /// Checks that the names of items don't collide with external crates.
1231
- fn check_for_conflicts_between_external_crates_and_items ( & self ,
1232
- module : Module < ' a > ,
1233
- name : Name ,
1234
- span : Span ) {
1235
- if module. external_module_children . borrow ( ) . contains_key ( & name) {
1236
- resolve_error ( self , span, ResolutionError :: NameConflictsWithExternCrate ( name) ) ;
1237
- }
1238
- }
1239
-
1240
1222
/// Resolves the given module path from the given root `module_`.
1241
1223
fn resolve_module_path_from_root ( & mut self ,
1242
1224
module_ : Module < ' a > ,
@@ -1245,11 +1227,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1245
1227
span : Span ,
1246
1228
lp : LastPrivate )
1247
1229
-> ResolveResult < ( Module < ' a > , LastPrivate ) > {
1248
- fn search_parent_externals < ' a > ( needle : Name , module : Module < ' a > )
1249
- -> Option < Module < ' a > > {
1250
- match module. external_module_children . borrow ( ) . get ( & needle) {
1251
- Some ( _) => Some ( module) ,
1252
- None => match module. parent_link {
1230
+ fn search_parent_externals < ' a > ( needle : Name , module : Module < ' a > ) -> Option < Module < ' a > > {
1231
+ match module. get_child ( needle, TypeNS ) {
1232
+ Some ( ref binding) if binding. is_extern_crate ( ) => Some ( module) ,
1233
+ _ => match module. parent_link {
1253
1234
ModuleParentLink ( ref parent, _) => {
1254
1235
search_parent_externals ( needle, parent)
1255
1236
}
@@ -1480,17 +1461,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1480
1461
}
1481
1462
}
1482
1463
1483
- // Search for external modules.
1484
- if namespace == TypeNS {
1485
- let children = module_. external_module_children . borrow ( ) ;
1486
- if let Some ( module) = children. get ( & name) {
1487
- let name_binding = NameBinding :: create_from_module ( module, None ) ;
1488
- debug ! ( "lower name bindings succeeded" ) ;
1489
- return Success ( ( Target :: new ( module_, name_binding, Shadowable :: Never ) ,
1490
- false ) ) ;
1491
- }
1492
- }
1493
-
1494
1464
// Finally, proceed up the scope chain looking for parent modules.
1495
1465
let mut search_module = module_;
1496
1466
loop {
@@ -1684,16 +1654,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1684
1654
Some ( ..) | None => { } // Continue.
1685
1655
}
1686
1656
1687
- // Finally, search through external children.
1688
- if namespace == TypeNS {
1689
- let children = module_. external_module_children . borrow ( ) ;
1690
- if let Some ( module) = children. get ( & name) {
1691
- let name_binding = NameBinding :: create_from_module ( module, None ) ;
1692
- return Success ( ( Target :: new ( module_, name_binding, Shadowable :: Never ) ,
1693
- false ) ) ;
1694
- }
1695
- }
1696
-
1697
1657
// We're out of luck.
1698
1658
debug ! ( "(resolving name in module) failed to resolve `{}`" , name) ;
1699
1659
return Failed ( None ) ;
@@ -1712,7 +1672,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1712
1672
// Descend into children and anonymous children.
1713
1673
build_reduced_graph:: populate_module_if_necessary ( self , & module_) ;
1714
1674
1715
- for ( _, child_node ) in module_ . children . borrow ( ) . iter ( ) {
1675
+ module_ . for_each_local_child ( | _, _ , child_node| {
1716
1676
match child_node. module ( ) {
1717
1677
None => {
1718
1678
// Continue.
@@ -1721,7 +1681,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1721
1681
self . report_unresolved_imports ( child_module) ;
1722
1682
}
1723
1683
}
1724
- }
1684
+ } ) ;
1725
1685
1726
1686
for ( _, module_) in module_. anonymous_children . borrow ( ) . iter ( ) {
1727
1687
self . report_unresolved_imports ( module_) ;
0 commit comments