@@ -120,8 +120,6 @@ enum SuggestionType {
120120}
121121
122122pub enum ResolutionError < ' a > {
123- /// error E0260: name conflicts with an extern crate
124- NameConflictsWithExternCrate ( Name ) ,
125123 /// error E0401: can't use type parameters from outer function
126124 TypeParametersFromOuterFunction ,
127125 /// 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>,
228226 }
229227
230228 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- }
239229 ResolutionError :: TypeParametersFromOuterFunction => {
240230 struct_span_err ! ( resolver. session,
241231 span,
@@ -801,14 +791,11 @@ pub struct ModuleS<'a> {
801791 parent_link : ParentLink < ' a > ,
802792 def : Cell < Option < Def > > ,
803793 is_public : bool ,
794+ is_extern_crate : bool ,
804795
805796 children : RefCell < HashMap < ( Name , Namespace ) , NameBinding < ' a > > > ,
806797 imports : RefCell < Vec < ImportDirective > > ,
807798
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-
812799 // The anonymous children of this node. Anonymous children are pseudo-
813800 // modules that are implicitly created around items contained within
814801 // blocks.
@@ -854,9 +841,9 @@ impl<'a> ModuleS<'a> {
854841 parent_link : parent_link,
855842 def : Cell :: new ( def) ,
856843 is_public : is_public,
844+ is_extern_crate : false ,
857845 children : RefCell :: new ( HashMap :: new ( ) ) ,
858846 imports : RefCell :: new ( Vec :: new ( ) ) ,
859- external_module_children : RefCell :: new ( HashMap :: new ( ) ) ,
860847 anonymous_children : RefCell :: new ( NodeMap ( ) ) ,
861848 import_resolutions : RefCell :: new ( HashMap :: new ( ) ) ,
862849 glob_count : Cell :: new ( 0 ) ,
@@ -871,10 +858,21 @@ impl<'a> ModuleS<'a> {
871858 self . children . borrow ( ) . get ( & ( name, ns) ) . cloned ( )
872859 }
873860
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 > > {
875865 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+ }
878876 }
879877 }
880878
@@ -1005,6 +1003,10 @@ impl<'a> NameBinding<'a> {
10051003 let def = self . def ( ) . unwrap ( ) ;
10061004 ( def, LastMod ( if self . is_public ( ) { AllPublic } else { DependsOn ( def. def_id ( ) ) } ) )
10071005 }
1006+
1007+ fn is_extern_crate ( & self ) -> bool {
1008+ self . module ( ) . map ( |module| module. is_extern_crate ) . unwrap_or ( false )
1009+ }
10081010}
10091011
10101012/// Interns the names of the primitive types.
@@ -1184,6 +1186,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11841186 self . arenas . modules . alloc ( ModuleS :: new ( parent_link, def, external, is_public) )
11851187 }
11861188
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+
11871195 fn get_ribs < ' b > ( & ' b mut self , ns : Namespace ) -> & ' b mut Vec < Rib < ' a > > {
11881196 match ns { ValueNS => & mut self . value_ribs , TypeNS => & mut self . type_ribs }
11891197 }
@@ -1211,32 +1219,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12111219 }
12121220 }
12131221
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-
12401222 /// Resolves the given module path from the given root `module_`.
12411223 fn resolve_module_path_from_root ( & mut self ,
12421224 module_ : Module < ' a > ,
@@ -1245,11 +1227,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12451227 span : Span ,
12461228 lp : LastPrivate )
12471229 -> 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 {
12531234 ModuleParentLink ( ref parent, _) => {
12541235 search_parent_externals ( needle, parent)
12551236 }
@@ -1480,17 +1461,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14801461 }
14811462 }
14821463
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-
14941464 // Finally, proceed up the scope chain looking for parent modules.
14951465 let mut search_module = module_;
14961466 loop {
@@ -1684,16 +1654,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16841654 Some ( ..) | None => { } // Continue.
16851655 }
16861656
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-
16971657 // We're out of luck.
16981658 debug ! ( "(resolving name in module) failed to resolve `{}`" , name) ;
16991659 return Failed ( None ) ;
@@ -1712,7 +1672,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17121672 // Descend into children and anonymous children.
17131673 build_reduced_graph:: populate_module_if_necessary ( self , & module_) ;
17141674
1715- for ( _, child_node ) in module_ . children . borrow ( ) . iter ( ) {
1675+ module_ . for_each_local_child ( | _, _ , child_node| {
17161676 match child_node. module ( ) {
17171677 None => {
17181678 // Continue.
@@ -1721,7 +1681,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17211681 self . report_unresolved_imports ( child_module) ;
17221682 }
17231683 }
1724- }
1684+ } ) ;
17251685
17261686 for ( _, module_) in module_. anonymous_children . borrow ( ) . iter ( ) {
17271687 self . report_unresolved_imports ( module_) ;
0 commit comments