18
18
#![ cfg_attr( not( stage0) , deny( warnings) ) ]
19
19
20
20
#![ feature( associated_consts) ]
21
+ #![ feature( borrow_state) ]
21
22
#![ feature( rustc_diagnostic_macros) ]
22
23
#![ feature( rustc_private) ]
23
24
#![ feature( staged_api) ]
@@ -832,6 +833,9 @@ pub struct ModuleS<'a> {
832
833
833
834
shadowed_traits : RefCell < Vec < & ' a NameBinding < ' a > > > ,
834
835
836
+ glob_importers : RefCell < Vec < ( Module < ' a > , & ' a ImportDirective ) > > ,
837
+ resolved_globs : RefCell < ( Vec < Module < ' a > > /* public */ , Vec < Module < ' a > > /* private */ ) > ,
838
+
835
839
// The number of unresolved globs that this module exports.
836
840
glob_count : Cell < usize > ,
837
841
@@ -866,6 +870,8 @@ impl<'a> ModuleS<'a> {
866
870
unresolved_imports : RefCell :: new ( Vec :: new ( ) ) ,
867
871
module_children : RefCell :: new ( NodeMap ( ) ) ,
868
872
shadowed_traits : RefCell :: new ( Vec :: new ( ) ) ,
873
+ glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
874
+ resolved_globs : RefCell :: new ( ( Vec :: new ( ) , Vec :: new ( ) ) ) ,
869
875
glob_count : Cell :: new ( 0 ) ,
870
876
pub_count : Cell :: new ( 0 ) ,
871
877
pub_glob_count : Cell :: new ( 0 ) ,
@@ -874,54 +880,11 @@ impl<'a> ModuleS<'a> {
874
880
}
875
881
}
876
882
877
- fn resolve_name ( & self , name : Name , ns : Namespace , allow_private_imports : bool )
878
- -> ResolveResult < & ' a NameBinding < ' a > > {
879
- let glob_count =
880
- if allow_private_imports { self . glob_count . get ( ) } else { self . pub_glob_count . get ( ) } ;
881
-
882
- self . resolutions . borrow ( ) . get ( & ( name, ns) ) . cloned ( ) . unwrap_or_default ( ) . result ( glob_count)
883
- . and_then ( |binding| {
884
- let allowed = allow_private_imports || !binding. is_import ( ) || binding. is_public ( ) ;
885
- if allowed { Success ( binding) } else { Failed ( None ) }
886
- } )
887
- }
888
-
889
- // Define the name or return the existing binding if there is a collision.
890
- fn try_define_child ( & self , name : Name , ns : Namespace , binding : NameBinding < ' a > )
891
- -> Result < ( ) , & ' a NameBinding < ' a > > {
892
- let binding = self . arenas . alloc_name_binding ( binding) ;
893
- let mut children = self . resolutions . borrow_mut ( ) ;
894
- let resolution = children. entry ( ( name, ns) ) . or_insert_with ( Default :: default) ;
895
-
896
- // FIXME #31379: We can use methods from imported traits shadowed by non-import items
897
- if let Some ( old_binding) = resolution. binding {
898
- if !old_binding. is_import ( ) && binding. is_import ( ) {
899
- if let Some ( Def :: Trait ( _) ) = binding. def ( ) {
900
- self . shadowed_traits . borrow_mut ( ) . push ( binding) ;
901
- }
902
- }
903
- }
904
-
905
- resolution. try_define ( binding)
906
- }
907
-
908
883
fn add_import_directive ( & self , import_directive : ImportDirective ) {
909
884
let import_directive = self . arenas . alloc_import_directive ( import_directive) ;
910
885
self . unresolved_imports . borrow_mut ( ) . push ( import_directive) ;
911
886
}
912
887
913
- fn increment_outstanding_references_for ( & self , name : Name , ns : Namespace ) {
914
- let mut children = self . resolutions . borrow_mut ( ) ;
915
- children. entry ( ( name, ns) ) . or_insert_with ( Default :: default) . outstanding_references += 1 ;
916
- }
917
-
918
- fn decrement_outstanding_references_for ( & self , name : Name , ns : Namespace ) {
919
- match self . resolutions . borrow_mut ( ) . get_mut ( & ( name, ns) ) . unwrap ( ) . outstanding_references {
920
- 0 => panic ! ( "No more outstanding references!" ) ,
921
- ref mut outstanding_references => { * outstanding_references -= 1 ; }
922
- }
923
- }
924
-
925
888
fn for_each_child < F : FnMut ( Name , Namespace , & ' a NameBinding < ' a > ) > ( & self , mut f : F ) {
926
889
for ( & ( name, ns) , name_resolution) in self . resolutions . borrow ( ) . iter ( ) {
927
890
name_resolution. binding . map ( |binding| f ( name, ns, binding) ) ;
0 commit comments