@@ -1023,12 +1023,19 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
1023
1023
span : Span , // span of the field pattern, e.g., `x: 0`
1024
1024
def : & ' tcx ty:: AdtDef , // definition of the struct or enum
1025
1025
field : & ' tcx ty:: FieldDef ,
1026
+ in_update_syntax : bool ,
1026
1027
) {
1027
1028
// definition of the field
1028
1029
let ident = Ident :: new ( kw:: Invalid , use_ctxt) ;
1029
1030
let current_hir = self . current_item ;
1030
1031
let def_id = self . tcx . adjust_ident_and_get_scope ( ident, def. did , current_hir) . 1 ;
1031
1032
if !def. is_enum ( ) && !field. vis . is_accessible_from ( def_id, self . tcx ) {
1033
+ let label = if in_update_syntax {
1034
+ format ! ( "field `{}` is private" , field. ident)
1035
+ } else {
1036
+ "private field" . to_string ( )
1037
+ } ;
1038
+
1032
1039
struct_span_err ! (
1033
1040
self . tcx. sess,
1034
1041
span,
@@ -1038,7 +1045,7 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
1038
1045
def. variant_descr( ) ,
1039
1046
self . tcx. def_path_str( def. did)
1040
1047
)
1041
- . span_label ( span, "private field" )
1048
+ . span_label ( span, label )
1042
1049
. emit ( ) ;
1043
1050
}
1044
1051
}
@@ -1106,13 +1113,13 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
1106
1113
Some ( field) => ( field. ident . span , field. span ) ,
1107
1114
None => ( base. span , base. span ) ,
1108
1115
} ;
1109
- self . check_field ( use_ctxt, span, adt, variant_field) ;
1116
+ self . check_field ( use_ctxt, span, adt, variant_field, true ) ;
1110
1117
}
1111
1118
} else {
1112
1119
for field in fields {
1113
1120
let use_ctxt = field. ident . span ;
1114
1121
let index = self . tcx . field_index ( field. hir_id , self . tables ) ;
1115
- self . check_field ( use_ctxt, field. span , adt, & variant. fields [ index] ) ;
1122
+ self . check_field ( use_ctxt, field. span , adt, & variant. fields [ index] , false ) ;
1116
1123
}
1117
1124
}
1118
1125
}
@@ -1131,7 +1138,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
1131
1138
for field in fields {
1132
1139
let use_ctxt = field. ident . span ;
1133
1140
let index = self . tcx . field_index ( field. hir_id , self . tables ) ;
1134
- self . check_field ( use_ctxt, field. span , adt, & variant. fields [ index] ) ;
1141
+ self . check_field ( use_ctxt, field. span , adt, & variant. fields [ index] , false ) ;
1135
1142
}
1136
1143
}
1137
1144
_ => { }
0 commit comments