@@ -22,12 +22,12 @@ use rustc::lint;
22
22
use rustc:: middle:: privacy:: { AccessLevel , AccessLevels } ;
23
23
use rustc:: ty:: { self , TyCtxt , Ty , TraitRef , TypeFoldable , GenericParamDefKind } ;
24
24
use rustc:: ty:: fold:: TypeVisitor ;
25
- use rustc:: ty:: query:: Providers ;
25
+ use rustc:: ty:: query:: { Providers , queries } ;
26
26
use rustc:: ty:: subst:: Substs ;
27
27
use rustc:: util:: nodemap:: NodeSet ;
28
28
use rustc_data_structures:: fx:: FxHashSet ;
29
29
use rustc_data_structures:: sync:: Lrc ;
30
- use syntax:: ast:: { self , CRATE_NODE_ID , Ident } ;
30
+ use syntax:: ast:: { self , DUMMY_NODE_ID , Ident } ;
31
31
use syntax:: attr;
32
32
use syntax:: symbol:: keywords;
33
33
use syntax_pos:: Span ;
@@ -782,6 +782,10 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
782
782
NestedVisitorMap :: All ( & self . tcx . hir ( ) )
783
783
}
784
784
785
+ fn visit_mod ( & mut self , _m : & ' tcx hir:: Mod , _s : Span , _n : ast:: NodeId ) {
786
+ // Don't visit modules inside
787
+ }
788
+
785
789
fn visit_nested_body ( & mut self , body : hir:: BodyId ) {
786
790
let orig_tables = mem:: replace ( & mut self . tables , self . tcx . body_tables ( body) ) ;
787
791
let body = self . tcx . hir ( ) . body ( body) ;
@@ -917,6 +921,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
917
921
NestedVisitorMap :: All ( & self . tcx . hir ( ) )
918
922
}
919
923
924
+ fn visit_mod ( & mut self , _m : & ' tcx hir:: Mod , _s : Span , _n : ast:: NodeId ) {
925
+ // Don't visit modules inside
926
+ }
927
+
920
928
fn visit_nested_body ( & mut self , body : hir:: BodyId ) {
921
929
let orig_tables = mem:: replace ( & mut self . tables , self . tcx . body_tables ( body) ) ;
922
930
let orig_in_body = mem:: replace ( & mut self . in_body , true ) ;
@@ -1659,6 +1667,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
1659
1667
pub fn provide ( providers : & mut Providers ) {
1660
1668
* providers = Providers {
1661
1669
privacy_access_levels,
1670
+ check_mod_privacy,
1662
1671
..* providers
1663
1672
} ;
1664
1673
}
@@ -1667,34 +1676,43 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Lrc<AccessLevels> {
1667
1676
tcx. privacy_access_levels ( LOCAL_CRATE )
1668
1677
}
1669
1678
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 ( ) ;
1679
+ fn check_mod_privacy < ' tcx > ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > , module_def_id : DefId ) {
1676
1680
let empty_tables = ty:: TypeckTables :: empty ( None ) ;
1677
1681
1678
1682
// Check privacy of names not checked in previous compilation stages.
1679
1683
let mut visitor = NamePrivacyVisitor {
1680
1684
tcx,
1681
1685
tables : & empty_tables,
1682
- current_item : CRATE_NODE_ID ,
1686
+ current_item : DUMMY_NODE_ID ,
1683
1687
empty_tables : & empty_tables,
1684
1688
} ;
1685
- intravisit:: walk_crate ( & mut visitor, krate) ;
1689
+ let ( module, span, node_id) = tcx. hir ( ) . get_module ( module_def_id) ;
1690
+ intravisit:: walk_mod ( & mut visitor, module, node_id) ;
1686
1691
1687
1692
// Check privacy of explicitly written types and traits as well as
1688
1693
// inferred types of expressions and patterns.
1689
1694
let mut visitor = TypePrivacyVisitor {
1690
1695
tcx,
1691
1696
tables : & empty_tables,
1692
- current_item : DefId :: local ( CRATE_DEF_INDEX ) ,
1697
+ current_item : module_def_id ,
1693
1698
in_body : false ,
1694
- span : krate . span ,
1699
+ span,
1695
1700
empty_tables : & empty_tables,
1696
1701
} ;
1697
- intravisit:: walk_crate ( & mut visitor, krate) ;
1702
+ intravisit:: walk_mod ( & mut visitor, module, node_id) ;
1703
+ }
1704
+
1705
+ fn privacy_access_levels < ' tcx > (
1706
+ tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
1707
+ krate : CrateNum ,
1708
+ ) -> Lrc < AccessLevels > {
1709
+ assert_eq ! ( krate, LOCAL_CRATE ) ;
1710
+
1711
+ let krate = tcx. hir ( ) . krate ( ) ;
1712
+
1713
+ for & module in tcx. hir ( ) . krate ( ) . modules . keys ( ) {
1714
+ queries:: check_mod_privacy:: ensure ( tcx, tcx. hir ( ) . local_def_id ( module) ) ;
1715
+ }
1698
1716
1699
1717
// Build up a set of all exported items in the AST. This is a set of all
1700
1718
// items which are reachable from external crates based on visibility.
0 commit comments