@@ -390,8 +390,8 @@ enum PrivacyResult {
390
390
391
391
enum FieldName {
392
392
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 ) ,
395
395
}
396
396
397
397
impl < ' a , ' tcx > PrivacyVisitor < ' a , ' tcx > {
@@ -665,9 +665,9 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
665
665
name : FieldName ) {
666
666
let fields = ty:: lookup_struct_fields ( self . tcx , id) ;
667
667
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 ( )
671
671
}
672
672
UnnamedField ( idx) => & fields[ idx]
673
673
} ;
@@ -686,7 +686,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
686
686
} ;
687
687
let msg = match name {
688
688
NamedField ( name) => format ! ( "field `{}` of {} is private" ,
689
- token:: get_ident ( name) , struct_desc) ,
689
+ token:: get_name ( name) , struct_desc) ,
690
690
UnnamedField ( idx) => format ! ( "field #{} of {} is private" ,
691
691
idx + 1 , struct_desc) ,
692
692
} ;
@@ -873,7 +873,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
873
873
match expr. node {
874
874
ast:: ExprField ( ref base, ident) => {
875
875
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 ) ) ;
877
877
}
878
878
}
879
879
ast:: ExprTupField ( ref base, idx) => {
@@ -897,18 +897,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
897
897
}
898
898
ast:: ExprStruct ( _, ref fields, _) => {
899
899
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 ) ) ;
904
905
}
905
906
}
906
907
ty:: ty_enum( _, _) => {
907
908
match self . tcx . def_map . borrow ( ) [ expr. id ] . clone ( ) {
908
909
def:: DefVariant ( _, variant_id, _) => {
909
910
for field in fields {
910
911
self . check_field ( expr. span , variant_id,
911
- NamedField ( field. ident . node ) ) ;
912
+ NamedField ( field. ident . node . name ) ) ;
912
913
}
913
914
}
914
915
_ => self . tcx . sess . span_bug ( expr. span ,
@@ -973,15 +974,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
973
974
ty:: ty_struct( id, _) => {
974
975
for field in fields {
975
976
self . check_field ( pattern. span , id,
976
- NamedField ( field. node . ident ) ) ;
977
+ NamedField ( field. node . ident . name ) ) ;
977
978
}
978
979
}
979
980
ty:: ty_enum( _, _) => {
980
981
match self . tcx . def_map . borrow ( ) . get ( & pattern. id ) {
981
982
Some ( & def:: DefVariant ( _, variant_id, _) ) => {
982
983
for field in fields {
983
984
self . check_field ( pattern. span , variant_id,
984
- NamedField ( field. node . ident ) ) ;
985
+ NamedField ( field. node . ident . name ) ) ;
985
986
}
986
987
}
987
988
_ => self . tcx . sess . span_bug ( pattern. span ,
0 commit comments