@@ -969,6 +969,10 @@ pub struct Resolver<'a> {
969
969
// The module that represents the current item scope.
970
970
current_module : Module < ' a > ,
971
971
972
+ // The visibility of `pub(self)` items in the current scope.
973
+ // Equivalently, the visibility required for an item to be accessible from the current scope.
974
+ current_vis : ty:: Visibility ,
975
+
972
976
// The current set of local scopes, for values.
973
977
// FIXME #4948: Reuse ribs to avoid allocation.
974
978
value_ribs : Vec < Rib < ' a > > ,
@@ -1154,6 +1158,7 @@ impl<'a> Resolver<'a> {
1154
1158
indeterminate_imports : Vec :: new ( ) ,
1155
1159
1156
1160
current_module : graph_root,
1161
+ current_vis : ty:: Visibility :: Restricted ( ast:: CRATE_NODE_ID ) ,
1157
1162
value_ribs : vec ! [ Rib :: new( ModuleRibKind ( graph_root) ) ] ,
1158
1163
type_ribs : vec ! [ Rib :: new( ModuleRibKind ( graph_root) ) ] ,
1159
1164
label_ribs : Vec :: new ( ) ,
@@ -1197,6 +1202,7 @@ impl<'a> Resolver<'a> {
1197
1202
/// Entry point to crate resolution.
1198
1203
pub fn resolve_crate ( & mut self , krate : & Crate ) {
1199
1204
self . current_module = self . graph_root ;
1205
+ self . current_vis = ty:: Visibility :: Restricted ( ast:: CRATE_NODE_ID ) ;
1200
1206
visit:: walk_crate ( self , krate) ;
1201
1207
1202
1208
check_unused:: check_crate ( self , krate) ;
@@ -1562,13 +1568,15 @@ impl<'a> Resolver<'a> {
1562
1568
let module = self . module_map . get ( & id) . cloned ( ) ; // clones a reference
1563
1569
if let Some ( module) = module {
1564
1570
// Move down in the graph.
1565
- let orig_module = :: std:: mem:: replace ( & mut self . current_module , module) ;
1571
+ let orig_module = replace ( & mut self . current_module , module) ;
1572
+ let orig_vis = replace ( & mut self . current_vis , ty:: Visibility :: Restricted ( id) ) ;
1566
1573
self . value_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
1567
1574
self . type_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
1568
1575
1569
1576
f ( self ) ;
1570
1577
1571
1578
self . current_module = orig_module;
1579
+ self . current_vis = orig_vis;
1572
1580
self . value_ribs . pop ( ) ;
1573
1581
self . type_ribs . pop ( ) ;
1574
1582
} else {
@@ -2706,7 +2714,6 @@ impl<'a> Resolver<'a> {
2706
2714
fn with_empty_ribs < T , F > ( & mut self , f : F ) -> T
2707
2715
where F : FnOnce ( & mut Resolver < ' a > ) -> T ,
2708
2716
{
2709
- use :: std:: mem:: replace;
2710
2717
let value_ribs = replace ( & mut self . value_ribs , Vec :: new ( ) ) ;
2711
2718
let type_ribs = replace ( & mut self . type_ribs , Vec :: new ( ) ) ;
2712
2719
let label_ribs = replace ( & mut self . label_ribs , Vec :: new ( ) ) ;
@@ -3264,13 +3271,7 @@ impl<'a> Resolver<'a> {
3264
3271
ast:: Visibility :: Public => return ty:: Visibility :: Public ,
3265
3272
ast:: Visibility :: Crate ( _) => return ty:: Visibility :: Restricted ( ast:: CRATE_NODE_ID ) ,
3266
3273
ast:: Visibility :: Restricted { ref path, id } => ( path, id) ,
3267
- ast:: Visibility :: Inherited => {
3268
- let current_module =
3269
- self . get_nearest_normal_module_parent_or_self ( self . current_module ) ;
3270
- let id =
3271
- self . definitions . as_local_node_id ( current_module. def_id ( ) . unwrap ( ) ) . unwrap ( ) ;
3272
- return ty:: Visibility :: Restricted ( id) ;
3273
- }
3274
+ ast:: Visibility :: Inherited => return self . current_vis ,
3274
3275
} ;
3275
3276
3276
3277
let segments: Vec < _ > = path. segments . iter ( ) . map ( |seg| seg. identifier . name ) . collect ( ) ;
@@ -3299,9 +3300,7 @@ impl<'a> Resolver<'a> {
3299
3300
}
3300
3301
3301
3302
fn is_accessible ( & self , vis : ty:: Visibility ) -> bool {
3302
- let current_module = self . get_nearest_normal_module_parent_or_self ( self . current_module ) ;
3303
- let node_id = self . definitions . as_local_node_id ( current_module. def_id ( ) . unwrap ( ) ) . unwrap ( ) ;
3304
- vis. is_accessible_from ( node_id, self )
3303
+ vis. is_at_least ( self . current_vis , self )
3305
3304
}
3306
3305
3307
3306
fn check_privacy ( & mut self , name : Name , binding : & ' a NameBinding < ' a > , span : Span ) {
0 commit comments