@@ -1215,38 +1215,49 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1215
1215
}
1216
1216
} ,
1217
1217
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) ) ) ;
1218
+ match variant. ctor_kind {
1219
+ CtorKind :: Fn => {
1220
+ err. span_label ( field. ident . span , "field does not exist" ) ;
1221
+ err. span_label (
1222
+ field. ident . span ,
1223
+ format ! ( "`{adt}` is a tuple {kind_name}, use the appropriate syntax: `{adt}(/* fields */)`" , adt=ty, kind_name=kind_name)
1224
+ ) ;
1225
+ }
1226
+ _ => {
1227
+ // prevent all specified fields from being suggested
1228
+ let skip_fields = skip_fields. iter ( ) . map ( |ref x| x. ident . as_str ( ) ) ;
1229
+ if let Some ( field_name) = Self :: suggest_field_name ( variant,
1230
+ & field. ident . as_str ( ) ,
1231
+ skip_fields. collect ( ) ) {
1232
+ err. span_suggestion (
1233
+ field. ident . span ,
1234
+ "a field with a similar name exists" ,
1235
+ field_name. to_string ( ) ,
1236
+ Applicability :: MaybeIncorrect ,
1237
+ ) ;
1238
+ } else {
1239
+ match ty. sty {
1240
+ ty:: Adt ( adt, ..) => {
1241
+ if adt. is_enum ( ) {
1242
+ err. span_label ( field. ident . span ,
1243
+ format ! ( "`{}::{}` does not have this field" ,
1244
+ ty, variant. ident) ) ;
1245
+ } else {
1246
+ err. span_label ( field. ident . span ,
1247
+ format ! ( "`{}` does not have this field" , ty) ) ;
1248
+ }
1249
+ let available_field_names = self . available_field_names ( variant) ;
1250
+ if !available_field_names. is_empty ( ) {
1251
+ err. note ( & format ! ( "available fields are: {}" ,
1252
+ self . name_series_display( available_field_names) ) ) ;
1253
+ }
1254
+ }
1255
+ _ => bug ! ( "non-ADT passed to report_unknown_field" )
1244
1256
}
1245
- }
1246
- _ => bug ! ( "non-ADT passed to report_unknown_field" )
1257
+ } ;
1247
1258
}
1248
- } ;
1249
- err. emit ( ) ;
1259
+ }
1260
+ err. emit ( ) ;
1250
1261
}
1251
1262
1252
1263
// Return an hint about the closest match in field names
0 commit comments