@@ -907,15 +907,6 @@ impl<'a> ModuleS<'a> {
907
907
_ => false ,
908
908
}
909
909
}
910
-
911
- fn is_ancestor_of ( & self , module : Module < ' a > ) -> bool {
912
- if self . def_id ( ) == module. def_id ( ) { return true }
913
- match module. parent_link {
914
- ParentLink :: BlockParentLink ( parent, _) |
915
- ParentLink :: ModuleParentLink ( parent, _) => self . is_ancestor_of ( parent) ,
916
- _ => false ,
917
- }
918
- }
919
910
}
920
911
921
912
impl < ' a > fmt:: Debug for ModuleS < ' a > {
@@ -1330,7 +1321,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1330
1321
// Check to see whether there are type bindings, and, if
1331
1322
// so, whether there is a module within.
1332
1323
if let Some ( module_def) = binding. module ( ) {
1333
- self . check_privacy ( search_module , name, binding, span) ;
1324
+ self . check_privacy ( name, binding, span) ;
1334
1325
search_module = module_def;
1335
1326
} else {
1336
1327
let msg = format ! ( "Not a module `{}`" , name) ;
@@ -1461,7 +1452,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1461
1452
}
1462
1453
1463
1454
/// Returns the nearest normal module parent of the given module.
1464
- fn get_nearest_normal_module_parent ( & mut self , module_ : Module < ' a > ) -> Option < Module < ' a > > {
1455
+ fn get_nearest_normal_module_parent ( & self , module_ : Module < ' a > ) -> Option < Module < ' a > > {
1465
1456
let mut module_ = module_;
1466
1457
loop {
1467
1458
match module_. parent_link {
@@ -1480,7 +1471,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1480
1471
1481
1472
/// Returns the nearest normal module parent of the given module, or the
1482
1473
/// module itself if it is a normal module.
1483
- fn get_nearest_normal_module_parent_or_self ( & mut self , module_ : Module < ' a > ) -> Module < ' a > {
1474
+ fn get_nearest_normal_module_parent_or_self ( & self , module_ : Module < ' a > ) -> Module < ' a > {
1484
1475
if module_. is_normal ( ) {
1485
1476
return module_;
1486
1477
}
@@ -2768,7 +2759,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2768
2759
let name = segments. last ( ) . unwrap ( ) . identifier . name ;
2769
2760
let result = self . resolve_name_in_module ( containing_module, name, namespace, false , true ) ;
2770
2761
result. success ( ) . map ( |binding| {
2771
- self . check_privacy ( containing_module , name, binding, span) ;
2762
+ self . check_privacy ( name, binding, span) ;
2772
2763
binding. def ( ) . unwrap ( )
2773
2764
} ) . ok_or ( false )
2774
2765
}
@@ -2818,7 +2809,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2818
2809
let name = segments. last ( ) . unwrap ( ) . identifier . name ;
2819
2810
let result = self . resolve_name_in_module ( containing_module, name, namespace, false , true ) ;
2820
2811
result. success ( ) . map ( |binding| {
2821
- self . check_privacy ( containing_module , name, binding, span) ;
2812
+ self . check_privacy ( name, binding, span) ;
2822
2813
binding. def ( ) . unwrap ( )
2823
2814
} ) . ok_or ( false )
2824
2815
}
@@ -3412,16 +3403,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3412
3403
vis
3413
3404
}
3414
3405
3415
- fn is_visible ( & self , binding : & ' a NameBinding < ' a > , parent : Module < ' a > ) -> bool {
3416
- binding. is_public ( ) || parent. is_ancestor_of ( self . current_module )
3406
+ fn is_accessible ( & self , vis : ty:: Visibility ) -> bool {
3407
+ let current_module = self . get_nearest_normal_module_parent_or_self ( self . current_module ) ;
3408
+ let node_id = self . ast_map . as_local_node_id ( current_module. def_id ( ) . unwrap ( ) ) . unwrap ( ) ;
3409
+ vis. is_accessible_from ( node_id, & self . ast_map )
3417
3410
}
3418
3411
3419
- fn check_privacy ( & mut self ,
3420
- module : Module < ' a > ,
3421
- name : Name ,
3422
- binding : & ' a NameBinding < ' a > ,
3423
- span : Span ) {
3424
- if !self . is_visible ( binding, module) {
3412
+ fn check_privacy ( & mut self , name : Name , binding : & ' a NameBinding < ' a > , span : Span ) {
3413
+ if !self . is_accessible ( binding. vis ) {
3425
3414
self . privacy_errors . push ( PrivacyError ( span, name, binding) ) ;
3426
3415
}
3427
3416
}
0 commit comments