@@ -1520,7 +1520,7 @@ impl<'a> Resolver<'a> {
15201520 pub fn resolve_crate ( & mut self , krate : & Crate ) {
15211521 self . session . time ( "resolve_crate" , || {
15221522 self . session . time ( "finalize_imports" , || ImportResolver { r : self } . finalize_imports ( ) ) ;
1523- self . session . time ( "prepare_privacy " , || self . prepare_privacy ( ) ) ;
1523+ self . session . time ( "resolve_exported_accesss_level " , || self . resolve_exported_accesss_level ( ) ) ;
15241524 self . session . time ( "finalize_macro_resolutions" , || self . finalize_macro_resolutions ( ) ) ;
15251525 self . session . time ( "late_resolve_crate" , || self . late_resolve_crate ( krate) ) ;
15261526 self . session . time ( "resolve_main" , || self . resolve_main ( ) ) ;
@@ -1530,20 +1530,22 @@ impl<'a> Resolver<'a> {
15301530 } ) ;
15311531 }
15321532
1533- fn prepare_privacy ( & mut self ) {
1533+ /// Compute access levels for exports and intermediate use statements
1534+ fn resolve_exported_accesss_level ( & mut self ) {
15341535 let root = self . graph_root ( ) ;
1535-
1536- if let Some ( def_id) = root. def_id ( ) {
1537- if let Some ( exports) = self . export_map . get ( & def_id. expect_local ( ) ) . cloned ( ) {
1538- let public_exports =
1539- exports. iter ( ) . filter ( |ex| ex. vis == Visibility :: Public ) . collect :: < Vec < _ > > ( ) ;
1540- for export in public_exports. into_iter ( ) {
1541- if let Some ( ns) = export. res . ns ( ) {
1542- let key = self . new_key ( export. ident , ns) ;
1543- let name_res = self . resolution ( root, key) ;
1544- if let Some ( binding) = name_res. borrow ( ) . binding ( ) {
1545- self . recursive_define_access_level ( binding, AccessLevel :: Public , 30 ) ;
1546- }
1536+ let exports = root. def_id ( ) . and_then ( |id| self . export_map . get ( & id. expect_local ( ) ) ) ;
1537+
1538+ if let Some ( exports) = exports. cloned ( ) {
1539+ let public_exports = exports. iter ( )
1540+ . filter ( |ex| ex. vis == Visibility :: Public )
1541+ . collect :: < Vec < _ > > ( ) ;
1542+
1543+ for export in public_exports {
1544+ if let Some ( ns) = export. res . ns ( ) {
1545+ let key = self . new_key ( export. ident , ns) ;
1546+ let name_res = self . resolution ( root, key) ;
1547+ if let Some ( binding) = name_res. borrow ( ) . binding ( ) {
1548+ self . compute_binding_access_level ( binding) ;
15471549 }
15481550 }
15491551 }
@@ -1552,25 +1554,17 @@ impl<'a> Resolver<'a> {
15521554 tracing:: debug!( "nodes_access_level: {:?}" , self . nodes_access_level) ;
15531555 }
15541556
1555- fn recursive_define_access_level (
1557+ /// Set the given binding access level to `AccessLevel::Public` and
1558+ /// sets the rest of the `use` chain to `AccessLevel::Exported` until
1559+ /// we hit the actual exported item
1560+ fn compute_binding_access_level (
15561561 & mut self ,
1557- binding : & NameBinding < ' a > ,
1558- access_level : AccessLevel ,
1559- max_recurse : usize ,
1562+ mut binding : & NameBinding < ' a >
15601563 ) {
1561- // Is this useful in case of very very veryyyyyy deep nesting?
1562- if max_recurse == 0 {
1563- return ;
1564- }
1565-
1566- if let NameBindingKind :: Import { binding, import, .. } = binding. kind {
1567- tracing:: trace!(
1568- "binding found! import.id={:?}, import.root_id={:?}, res={:?}" ,
1569- import. id,
1570- import. root_id,
1571- binding. res( )
1572- ) ;
1564+ let mut access_level = AccessLevel :: Public ;
1565+ while let NameBindingKind :: Import { binding : nested_binding, import, .. } = binding. kind {
15731566 self . mark_node_with_access_level ( import. id , access_level) ;
1567+
15741568 match import. kind {
15751569 ImportKind :: Single { additional_ids, .. } => {
15761570 self . mark_node_with_access_level ( additional_ids. 0 , access_level) ;
@@ -1579,7 +1573,8 @@ impl<'a> Resolver<'a> {
15791573 _ => { }
15801574 } ;
15811575
1582- self . recursive_define_access_level ( binding, AccessLevel :: Exported , max_recurse - 1 ) ;
1576+ access_level = AccessLevel :: Exported ;
1577+ binding = nested_binding;
15831578 }
15841579 }
15851580
0 commit comments