@@ -22,12 +22,12 @@ use rustc::lint;
2222use  rustc:: middle:: privacy:: { AccessLevel ,  AccessLevels } ; 
2323use  rustc:: ty:: { self ,  TyCtxt ,  Ty ,  TraitRef ,  TypeFoldable ,  GenericParamDefKind } ; 
2424use  rustc:: ty:: fold:: TypeVisitor ; 
25- use  rustc:: ty:: query:: Providers ; 
25+ use  rustc:: ty:: query:: { Providers ,  queries } ; 
2626use  rustc:: ty:: subst:: Substs ; 
2727use  rustc:: util:: nodemap:: NodeSet ; 
2828use  rustc_data_structures:: fx:: FxHashSet ; 
2929use  rustc_data_structures:: sync:: Lrc ; 
30- use  syntax:: ast:: { self ,  CRATE_NODE_ID ,  Ident } ; 
30+ use  syntax:: ast:: { self ,  DUMMY_NODE_ID ,  Ident } ; 
3131use  syntax:: attr; 
3232use  syntax:: symbol:: keywords; 
3333use  syntax_pos:: Span ; 
@@ -782,6 +782,11 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
782782        NestedVisitorMap :: All ( & self . tcx . hir ( ) ) 
783783    } 
784784
785+     fn  visit_mod ( & mut  self ,  _m :  & ' tcx  hir:: Mod ,  _s :  Span ,  _n :  ast:: NodeId )  { 
786+         // Don't visit nested modules, since we run a separate visitor walk 
787+         // for each module in `privacy_access_levels` 
788+     } 
789+ 
785790    fn  visit_nested_body ( & mut  self ,  body :  hir:: BodyId )  { 
786791        let  orig_tables = mem:: replace ( & mut  self . tables ,  self . tcx . body_tables ( body) ) ; 
787792        let  body = self . tcx . hir ( ) . body ( body) ; 
@@ -917,6 +922,11 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
917922        NestedVisitorMap :: All ( & self . tcx . hir ( ) ) 
918923    } 
919924
925+     fn  visit_mod ( & mut  self ,  _m :  & ' tcx  hir:: Mod ,  _s :  Span ,  _n :  ast:: NodeId )  { 
926+         // Don't visit nested modules, since we run a separate visitor walk 
927+         // for each module in `privacy_access_levels` 
928+     } 
929+ 
920930    fn  visit_nested_body ( & mut  self ,  body :  hir:: BodyId )  { 
921931        let  orig_tables = mem:: replace ( & mut  self . tables ,  self . tcx . body_tables ( body) ) ; 
922932        let  orig_in_body = mem:: replace ( & mut  self . in_body ,  true ) ; 
@@ -1659,6 +1669,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
16591669pub  fn  provide ( providers :  & mut  Providers )  { 
16601670    * providers = Providers  { 
16611671        privacy_access_levels, 
1672+         check_mod_privacy, 
16621673        ..* providers
16631674    } ; 
16641675} 
@@ -1667,34 +1678,43 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Lrc<AccessLevels> {
16671678    tcx. privacy_access_levels ( LOCAL_CRATE ) 
16681679} 
16691680
1670- fn  privacy_access_levels < ' a ,  ' tcx > ( tcx :  TyCtxt < ' a ,  ' tcx ,  ' tcx > , 
1671-                                    krate :  CrateNum ) 
1672-                                    -> Lrc < AccessLevels >  { 
1673-     assert_eq ! ( krate,  LOCAL_CRATE ) ; 
1674- 
1675-     let  krate = tcx. hir ( ) . krate ( ) ; 
1681+ fn  check_mod_privacy < ' tcx > ( tcx :  TyCtxt < ' _ ,  ' tcx ,  ' tcx > ,  module_def_id :  DefId )  { 
16761682    let  empty_tables = ty:: TypeckTables :: empty ( None ) ; 
16771683
16781684    // Check privacy of names not checked in previous compilation stages. 
16791685    let  mut  visitor = NamePrivacyVisitor  { 
16801686        tcx, 
16811687        tables :  & empty_tables, 
1682-         current_item :  CRATE_NODE_ID , 
1688+         current_item :  DUMMY_NODE_ID , 
16831689        empty_tables :  & empty_tables, 
16841690    } ; 
1685-     intravisit:: walk_crate ( & mut  visitor,  krate) ; 
1691+     let  ( module,  span,  node_id)  = tcx. hir ( ) . get_module ( module_def_id) ; 
1692+     intravisit:: walk_mod ( & mut  visitor,  module,  node_id) ; 
16861693
16871694    // Check privacy of explicitly written types and traits as well as 
16881695    // inferred types of expressions and patterns. 
16891696    let  mut  visitor = TypePrivacyVisitor  { 
16901697        tcx, 
16911698        tables :  & empty_tables, 
1692-         current_item :  DefId :: local ( CRATE_DEF_INDEX ) , 
1699+         current_item :  module_def_id , 
16931700        in_body :  false , 
1694-         span :  krate . span , 
1701+         span, 
16951702        empty_tables :  & empty_tables, 
16961703    } ; 
1697-     intravisit:: walk_crate ( & mut  visitor,  krate) ; 
1704+     intravisit:: walk_mod ( & mut  visitor,  module,  node_id) ; 
1705+ } 
1706+ 
1707+ fn  privacy_access_levels < ' tcx > ( 
1708+     tcx :  TyCtxt < ' _ ,  ' tcx ,  ' tcx > , 
1709+     krate :  CrateNum , 
1710+ )  -> Lrc < AccessLevels >  { 
1711+     assert_eq ! ( krate,  LOCAL_CRATE ) ; 
1712+ 
1713+     let  krate = tcx. hir ( ) . krate ( ) ; 
1714+ 
1715+     for  & module in  krate. modules . keys ( )  { 
1716+         queries:: check_mod_privacy:: ensure ( tcx,  tcx. hir ( ) . local_def_id ( module) ) ; 
1717+     } 
16981718
16991719    // Build up a set of all exported items in the AST. This is a set of all 
17001720    // items which are reachable from external crates based on visibility. 
0 commit comments