@@ -382,26 +382,18 @@ struct PrivacyVisitor<'a, 'tcx: 'a> {
382
382
}
383
383
384
384
impl < ' a , ' tcx > PrivacyVisitor < ' a , ' tcx > {
385
- fn item_is_visible ( & self , did : DefId ) -> bool {
386
- let is_public = match self . tcx . map . as_local_node_id ( did) {
387
- Some ( node_id) => self . tcx . map . expect_item ( node_id) . vis == hir:: Public ,
388
- None => self . tcx . sess . cstore . visibility ( did) == ty:: Visibility :: Public ,
389
- } ;
390
- is_public || self . private_accessible ( did)
391
- }
392
-
393
- /// True if `did` is private-accessible
394
- fn private_accessible ( & self , did : DefId ) -> bool {
385
+ fn item_is_accessible ( & self , did : DefId ) -> bool {
395
386
match self . tcx . map . as_local_node_id ( did) {
396
- Some ( node_id) => self . tcx . map . private_item_is_visible_from ( node_id, self . curitem ) ,
397
- None => false ,
398
- }
387
+ Some ( node_id) =>
388
+ ty:: Visibility :: from_hir ( & self . tcx . map . expect_item ( node_id) . vis , node_id, self . tcx ) ,
389
+ None => self . tcx . sess . cstore . visibility ( did) ,
390
+ } . is_accessible_from ( self . curitem , & self . tcx . map )
399
391
}
400
392
401
393
// Checks that a field is in scope.
402
394
fn check_field ( & mut self , span : Span , def : ty:: AdtDef < ' tcx > , field : ty:: FieldDef < ' tcx > ) {
403
395
if def. adt_kind ( ) == ty:: AdtKind :: Struct &&
404
- field. vis != ty :: Visibility :: Public && ! self . private_accessible ( def . did ) {
396
+ ! field. vis . is_accessible_from ( self . curitem , & self . tcx . map ) {
405
397
span_err ! ( self . tcx. sess, span, E0451 , "field `{}` of struct `{}` is private" ,
406
398
field. name, self . tcx. item_path_str( def. did) ) ;
407
399
}
@@ -412,7 +404,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
412
404
match self . tcx . impl_or_trait_item ( method_def_id) . container ( ) {
413
405
// Trait methods are always all public. The only controlling factor
414
406
// is whether the trait itself is accessible or not.
415
- ty:: TraitContainer ( trait_def_id) if !self . item_is_visible ( trait_def_id) => {
407
+ ty:: TraitContainer ( trait_def_id) if !self . item_is_accessible ( trait_def_id) => {
416
408
let msg = format ! ( "source trait `{}` is private" ,
417
409
self . tcx. item_path_str( trait_def_id) ) ;
418
410
self . tcx . sess . span_err ( span, & msg) ;
@@ -464,7 +456,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
464
456
_ => expr_ty
465
457
} . ty_adt_def ( ) . unwrap ( ) ;
466
458
let any_priv = def. struct_variant ( ) . fields . iter ( ) . any ( |f| {
467
- f. vis != ty :: Visibility :: Public && ! self . private_accessible ( def . did )
459
+ ! f. vis . is_accessible_from ( self . curitem , & self . tcx . map )
468
460
} ) ;
469
461
if any_priv {
470
462
span_err ! ( self . tcx. sess, expr. span, E0450 ,
0 commit comments