@@ -388,8 +388,8 @@ enum PrivacyResult {
388
388
389
389
enum FieldName {
390
390
UnnamedField ( uint ) , // index
391
- // FIXME #6993: change type (and name) from Ident to Name
392
- NamedField ( ast:: Ident ) ,
391
+ // (Name, not Ident, because struct fields are not macro-hygienic)
392
+ NamedField ( ast:: Name ) ,
393
393
}
394
394
395
395
impl < ' a , ' tcx > PrivacyVisitor < ' a , ' tcx > {
@@ -663,9 +663,9 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
663
663
name : FieldName ) {
664
664
let fields = ty:: lookup_struct_fields ( self . tcx , id) ;
665
665
let field = match name {
666
- NamedField ( ident ) => {
667
- debug ! ( "privacy - check named field {} in struct {:?}" , ident . name , id) ;
668
- fields. iter ( ) . find ( |f| f. name == ident . name ) . unwrap ( )
666
+ NamedField ( f_name ) => {
667
+ debug ! ( "privacy - check named field {} in struct {:?}" , f_name , id) ;
668
+ fields. iter ( ) . find ( |f| f. name == f_name ) . unwrap ( )
669
669
}
670
670
UnnamedField ( idx) => & fields[ idx]
671
671
} ;
@@ -684,7 +684,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
684
684
} ;
685
685
let msg = match name {
686
686
NamedField ( name) => format ! ( "field `{}` of {} is private" ,
687
- token:: get_ident ( name) , struct_desc) ,
687
+ token:: get_name ( name) , struct_desc) ,
688
688
UnnamedField ( idx) => format ! ( "field #{} of {} is private" ,
689
689
idx + 1 , struct_desc) ,
690
690
} ;
@@ -871,7 +871,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
871
871
match expr. node {
872
872
ast:: ExprField ( ref base, ident) => {
873
873
if let ty:: ty_struct( id, _) = ty:: expr_ty_adjusted ( self . tcx , & * * base) . sty {
874
- self . check_field ( expr. span , id, NamedField ( ident. node ) ) ;
874
+ self . check_field ( expr. span , id, NamedField ( ident. node . name ) ) ;
875
875
}
876
876
}
877
877
ast:: ExprTupField ( ref base, idx) => {
@@ -895,18 +895,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
895
895
}
896
896
ast:: ExprStruct ( _, ref fields, _) => {
897
897
match ty:: expr_ty ( self . tcx , expr) . sty {
898
- ty:: ty_struct( id, _) => {
899
- for field in ( * fields) . iter ( ) {
900
- self . check_field ( expr. span , id,
901
- NamedField ( field. ident . node ) ) ;
898
+ ty:: ty_struct( ctor_id, _) => {
899
+ let all_fields = ty:: lookup_struct_fields ( self . tcx , ctor_id) ;
900
+ for field in ( * all_fields) . iter ( ) {
901
+ self . check_field ( expr. span , ctor_id,
902
+ NamedField ( field. name ) ) ;
902
903
}
903
904
}
904
905
ty:: ty_enum( _, _) => {
905
906
match self . tcx . def_map . borrow ( ) [ expr. id ] . clone ( ) {
906
907
def:: DefVariant ( _, variant_id, _) => {
907
908
for field in fields. iter ( ) {
908
909
self . check_field ( expr. span , variant_id,
909
- NamedField ( field. ident . node ) ) ;
910
+ NamedField ( field. ident . node . name ) ) ;
910
911
}
911
912
}
912
913
_ => self . tcx . sess . span_bug ( expr. span ,
@@ -971,15 +972,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
971
972
ty:: ty_struct( id, _) => {
972
973
for field in fields. iter ( ) {
973
974
self . check_field ( pattern. span , id,
974
- NamedField ( field. node . ident ) ) ;
975
+ NamedField ( field. node . ident . name ) ) ;
975
976
}
976
977
}
977
978
ty:: ty_enum( _, _) => {
978
979
match self . tcx . def_map . borrow ( ) . get ( & pattern. id ) {
979
980
Some ( & def:: DefVariant ( _, variant_id, _) ) => {
980
981
for field in fields. iter ( ) {
981
982
self . check_field ( pattern. span , variant_id,
982
- NamedField ( field. node . ident ) ) ;
983
+ NamedField ( field. node . ident . name ) ) ;
983
984
}
984
985
}
985
986
_ => self . tcx . sess . span_bug ( pattern. span ,
0 commit comments