@@ -382,26 +382,18 @@ struct PrivacyVisitor<'a, 'tcx: 'a> {
382382}
383383
384384impl < ' 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 {
395386 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 )
399391 }
400392
401393 // Checks that a field is in scope.
402394 fn check_field ( & mut self , span : Span , def : ty:: AdtDef < ' tcx > , field : ty:: FieldDef < ' tcx > ) {
403395 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 ) {
405397 span_err ! ( self . tcx. sess, span, E0451 , "field `{}` of struct `{}` is private" ,
406398 field. name, self . tcx. item_path_str( def. did) ) ;
407399 }
@@ -412,7 +404,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
412404 match self . tcx . impl_or_trait_item ( method_def_id) . container ( ) {
413405 // Trait methods are always all public. The only controlling factor
414406 // 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) => {
416408 let msg = format ! ( "source trait `{}` is private" ,
417409 self . tcx. item_path_str( trait_def_id) ) ;
418410 self . tcx . sess . span_err ( span, & msg) ;
@@ -464,7 +456,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
464456 _ => expr_ty
465457 } . ty_adt_def ( ) . unwrap ( ) ;
466458 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 )
468460 } ) ;
469461 if any_priv {
470462 span_err ! ( self . tcx. sess, expr. span, E0450 ,
0 commit comments