@@ -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,22 @@ 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
+ // RFC 736: ensure all unmentioned fields are visible.
902
+ // Rather than computing the set of unmentioned fields
903
+ // (i.e. `all_fields - fields`), just check them all.
904
+ let all_fields = ty:: lookup_struct_fields ( self . tcx , ctor_id) ;
905
+ for field in all_fields {
906
+ self . check_field ( expr. span , ctor_id,
907
+ NamedField ( field. name ) ) ;
904
908
}
905
909
}
906
910
ty:: ty_enum( _, _) => {
907
911
match self . tcx . def_map . borrow ( ) [ expr. id ] . clone ( ) {
908
912
def:: DefVariant ( _, variant_id, _) => {
909
913
for field in fields {
910
914
self . check_field ( expr. span , variant_id,
911
- NamedField ( field. ident . node ) ) ;
915
+ NamedField ( field. ident . node . name ) ) ;
912
916
}
913
917
}
914
918
_ => self . tcx . sess . span_bug ( expr. span ,
@@ -973,15 +977,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
973
977
ty:: ty_struct( id, _) => {
974
978
for field in fields {
975
979
self . check_field ( pattern. span , id,
976
- NamedField ( field. node . ident ) ) ;
980
+ NamedField ( field. node . ident . name ) ) ;
977
981
}
978
982
}
979
983
ty:: ty_enum( _, _) => {
980
984
match self . tcx . def_map . borrow ( ) . get ( & pattern. id ) {
981
985
Some ( & def:: DefVariant ( _, variant_id, _) ) => {
982
986
for field in fields {
983
987
self . check_field ( pattern. span , variant_id,
984
- NamedField ( field. node . ident ) ) ;
988
+ NamedField ( field. node . ident . name ) ) ;
985
989
}
986
990
}
987
991
_ => self . tcx . sess . span_bug ( pattern. span ,
0 commit comments