@@ -390,8 +390,8 @@ enum PrivacyResult {
390390
391391enum FieldName {
392392 UnnamedField ( uint ) , // index
393- // FIXME #6993: change type (and name) from Ident to Name
394- NamedField ( ast:: Ident ) ,
393+ // (Name, not Ident, because struct fields are not macro-hygienic)
394+ NamedField ( ast:: Name ) ,
395395}
396396
397397impl < ' a , ' tcx > PrivacyVisitor < ' a , ' tcx > {
@@ -665,9 +665,9 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
665665 name : FieldName ) {
666666 let fields = ty:: lookup_struct_fields ( self . tcx , id) ;
667667 let field = match name {
668- NamedField ( ident ) => {
669- debug ! ( "privacy - check named field {} in struct {:?}" , ident . name , id) ;
670- fields. iter ( ) . find ( |f| f. name == ident . name ) . unwrap ( )
668+ NamedField ( f_name ) => {
669+ debug ! ( "privacy - check named field {} in struct {:?}" , f_name , id) ;
670+ fields. iter ( ) . find ( |f| f. name == f_name ) . unwrap ( )
671671 }
672672 UnnamedField ( idx) => & fields[ idx]
673673 } ;
@@ -686,7 +686,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
686686 } ;
687687 let msg = match name {
688688 NamedField ( name) => format ! ( "field `{}` of {} is private" ,
689- token:: get_ident ( name) , struct_desc) ,
689+ token:: get_name ( name) , struct_desc) ,
690690 UnnamedField ( idx) => format ! ( "field #{} of {} is private" ,
691691 idx + 1 , struct_desc) ,
692692 } ;
@@ -873,7 +873,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
873873 match expr. node {
874874 ast:: ExprField ( ref base, ident) => {
875875 if let ty:: ty_struct( id, _) = ty:: expr_ty_adjusted ( self . tcx , & * * base) . sty {
876- self . check_field ( expr. span , id, NamedField ( ident. node ) ) ;
876+ self . check_field ( expr. span , id, NamedField ( ident. node . name ) ) ;
877877 }
878878 }
879879 ast:: ExprTupField ( ref base, idx) => {
@@ -897,18 +897,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
897897 }
898898 ast:: ExprStruct ( _, ref fields, _) => {
899899 match ty:: expr_ty ( self . tcx , expr) . sty {
900- ty:: ty_struct( id, _) => {
901- for field in & ( * fields) {
902- self . check_field ( expr. span , id,
903- NamedField ( field. ident . node ) ) ;
900+ ty:: ty_struct( ctor_id, _) => {
901+ let all_fields = ty:: lookup_struct_fields ( self . tcx , ctor_id) ;
902+ for field in all_fields {
903+ self . check_field ( expr. span , ctor_id,
904+ NamedField ( field. name ) ) ;
904905 }
905906 }
906907 ty:: ty_enum( _, _) => {
907908 match self . tcx . def_map . borrow ( ) [ expr. id ] . clone ( ) {
908909 def:: DefVariant ( _, variant_id, _) => {
909910 for field in fields {
910911 self . check_field ( expr. span , variant_id,
911- NamedField ( field. ident . node ) ) ;
912+ NamedField ( field. ident . node . name ) ) ;
912913 }
913914 }
914915 _ => self . tcx . sess . span_bug ( expr. span ,
@@ -973,15 +974,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
973974 ty:: ty_struct( id, _) => {
974975 for field in fields {
975976 self . check_field ( pattern. span , id,
976- NamedField ( field. node . ident ) ) ;
977+ NamedField ( field. node . ident . name ) ) ;
977978 }
978979 }
979980 ty:: ty_enum( _, _) => {
980981 match self . tcx . def_map . borrow ( ) . get ( & pattern. id ) {
981982 Some ( & def:: DefVariant ( _, variant_id, _) ) => {
982983 for field in fields {
983984 self . check_field ( pattern. span , variant_id,
984- NamedField ( field. node . ident ) ) ;
985+ NamedField ( field. node . ident . name ) ) ;
985986 }
986987 }
987988 _ => self . tcx . sess . span_bug ( pattern. span ,
0 commit comments