@@ -692,32 +692,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
692692 /// whether the node is accessible by the current module that iteration is
693693 /// inside.
694694 fn private_accessible ( & self , id : ast:: NodeId ) -> bool {
695- let parent = * self . parents . get ( & id) . unwrap ( ) ;
696- debug ! ( "privacy - accessible parent {}" , self . nodestr( parent) ) ;
697-
698- // After finding `did`'s closest private member, we roll ourselves back
699- // to see if this private member's parent is anywhere in our ancestry.
700- // By the privacy rules, we can access all of our ancestor's private
701- // members, so that's why we test the parent, and not the did itself.
702- let mut cur = self . curitem ;
703- loop {
704- debug ! ( "privacy - questioning {}, {}" , self . nodestr( cur) , cur) ;
705- match cur {
706- // If the relevant parent is in our history, then we're allowed
707- // to look inside any of our ancestor's immediate private items,
708- // so this access is valid.
709- x if x == parent => return true ,
710-
711- // If we've reached the root, then we couldn't access this item
712- // in the first place
713- ast:: DUMMY_NODE_ID => return false ,
714-
715- // Keep going up
716- _ => { }
717- }
718-
719- cur = * self . parents . get ( & cur) . unwrap ( ) ;
720- }
695+ self . tcx . map . private_item_is_visible_from ( id, self . curitem )
721696 }
722697
723698 fn report_error ( & self , result : CheckResult ) -> bool {
@@ -835,7 +810,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
835810 }
836811 UnnamedField ( idx) => & v. fields [ idx]
837812 } ;
838- if field. vis == hir:: Public || self . local_private_accessible ( field . did ) {
813+ if field. vis == hir:: Public || self . local_private_accessible ( def . did ) {
839814 return ;
840815 }
841816
@@ -945,19 +920,9 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
945920 // def map is not. Therefore the names we work out below will not always
946921 // be accurate and we can get slightly wonky error messages (but type
947922 // checking is always correct).
948- match path_res. full_def ( ) {
949- Def :: Fn ( ..) => ck ( "function" ) ,
950- Def :: Static ( ..) => ck ( "static" ) ,
951- Def :: Const ( ..) => ck ( "const" ) ,
952- Def :: AssociatedConst ( ..) => ck ( "associated const" ) ,
953- Def :: Variant ( ..) => ck ( "variant" ) ,
954- Def :: TyAlias ( ..) => ck ( "type" ) ,
955- Def :: Enum ( ..) => ck ( "enum" ) ,
956- Def :: Trait ( ..) => ck ( "trait" ) ,
957- Def :: Struct ( ..) => ck ( "struct" ) ,
958- Def :: Method ( ..) => ck ( "method" ) ,
959- Def :: Mod ( ..) => ck ( "module" ) ,
960- _ => { }
923+ let def = path_res. full_def ( ) ;
924+ if def != Def :: Err {
925+ ck ( def. kind_name ( ) ) ;
961926 }
962927 }
963928
@@ -1036,7 +1001,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
10361001 _ => expr_ty
10371002 } . ty_adt_def ( ) . unwrap ( ) ;
10381003 let any_priv = def. struct_variant ( ) . fields . iter ( ) . any ( |f| {
1039- f. vis != hir:: Public && !self . local_private_accessible ( f . did )
1004+ f. vis != hir:: Public && !self . local_private_accessible ( def . did )
10401005 } ) ;
10411006 if any_priv {
10421007 span_err ! ( self . tcx. sess, expr. span, E0450 ,
0 commit comments