@@ -1125,7 +1125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1125
1125
1126
1126
err. emit ( ) ;
1127
1127
} else {
1128
- self . report_unknown_field ( adt_ty, variant, field, ast_fields, kind_name) ;
1128
+ self . report_unknown_field ( adt_ty, variant, field, ast_fields, kind_name, span ) ;
1129
1129
}
1130
1130
1131
1131
tcx. types . err
@@ -1196,6 +1196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1196
1196
field : & hir:: Field ,
1197
1197
skip_fields : & [ hir:: Field ] ,
1198
1198
kind_name : & str ,
1199
+ ty_span : Span
1199
1200
) {
1200
1201
if variant. recovered {
1201
1202
return ;
@@ -1215,37 +1216,57 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1215
1216
}
1216
1217
} ,
1217
1218
ty) ;
1218
- // prevent all specified fields from being suggested
1219
- let skip_fields = skip_fields. iter ( ) . map ( |ref x| x. ident . as_str ( ) ) ;
1220
- if let Some ( field_name) = Self :: suggest_field_name ( variant,
1221
- & field. ident . as_str ( ) ,
1222
- skip_fields. collect ( ) ) {
1223
- err. span_suggestion (
1224
- field. ident . span ,
1225
- "a field with a similar name exists" ,
1226
- field_name. to_string ( ) ,
1227
- Applicability :: MaybeIncorrect ,
1228
- ) ;
1229
- } else {
1230
- match ty. sty {
1231
- ty:: Adt ( adt, ..) => {
1232
- if adt. is_enum ( ) {
1233
- err. span_label ( field. ident . span ,
1234
- format ! ( "`{}::{}` does not have this field" ,
1235
- ty, variant. ident) ) ;
1236
- } else {
1237
- err. span_label ( field. ident . span ,
1238
- format ! ( "`{}` does not have this field" , ty) ) ;
1239
- }
1240
- let available_field_names = self . available_field_names ( variant) ;
1241
- if !available_field_names. is_empty ( ) {
1242
- err. note ( & format ! ( "available fields are: {}" ,
1243
- self . name_series_display( available_field_names) ) ) ;
1219
+ match variant. ctor_kind {
1220
+ CtorKind :: Fn => {
1221
+ err. span_label ( variant. ident . span , format ! ( "`{adt}` defined here" , adt=ty) ) ;
1222
+ err. span_label ( field. ident . span , "field does not exist" ) ;
1223
+ err. span_label ( ty_span, format ! (
1224
+ "`{adt}` is a tuple {kind_name}, \
1225
+ use the appropriate syntax: `{adt}(/* fields */)`",
1226
+ adt=ty,
1227
+ kind_name=kind_name
1228
+ ) ) ;
1229
+ }
1230
+ _ => {
1231
+ // prevent all specified fields from being suggested
1232
+ let skip_fields = skip_fields. iter ( ) . map ( |ref x| x. ident . as_str ( ) ) ;
1233
+ if let Some ( field_name) = Self :: suggest_field_name (
1234
+ variant,
1235
+ & field. ident . as_str ( ) ,
1236
+ skip_fields. collect ( )
1237
+ ) {
1238
+ err. span_suggestion (
1239
+ field. ident . span ,
1240
+ "a field with a similar name exists" ,
1241
+ field_name. to_string ( ) ,
1242
+ Applicability :: MaybeIncorrect ,
1243
+ ) ;
1244
+ } else {
1245
+ match ty. sty {
1246
+ ty:: Adt ( adt, ..) => {
1247
+ if adt. is_enum ( ) {
1248
+ err. span_label ( field. ident . span , format ! (
1249
+ "`{}::{}` does not have this field" ,
1250
+ ty,
1251
+ variant. ident
1252
+ ) ) ;
1253
+ } else {
1254
+ err. span_label ( field. ident . span , format ! (
1255
+ "`{}` does not have this field" ,
1256
+ ty
1257
+ ) ) ;
1258
+ }
1259
+ let available_field_names = self . available_field_names ( variant) ;
1260
+ if !available_field_names. is_empty ( ) {
1261
+ err. note ( & format ! ( "available fields are: {}" ,
1262
+ self . name_series_display( available_field_names) ) ) ;
1263
+ }
1264
+ }
1265
+ _ => bug ! ( "non-ADT passed to report_unknown_field" )
1244
1266
}
1245
- }
1246
- _ => bug ! ( "non-ADT passed to report_unknown_field" )
1267
+ } ;
1247
1268
}
1248
- } ;
1269
+ }
1249
1270
err. emit ( ) ;
1250
1271
}
1251
1272
0 commit comments