@@ -1125,7 +1125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11251125
11261126 err. emit ( ) ;
11271127 } 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 ) ;
11291129 }
11301130
11311131 tcx. types . err
@@ -1196,6 +1196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11961196 field : & hir:: Field ,
11971197 skip_fields : & [ hir:: Field ] ,
11981198 kind_name : & str ,
1199+ ty_span : Span
11991200 ) {
12001201 if variant. recovered {
12011202 return ;
@@ -1215,37 +1216,57 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12151216 }
12161217 } ,
12171218 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" )
12441266 }
1245- }
1246- _ => bug ! ( "non-ADT passed to report_unknown_field" )
1267+ } ;
12471268 }
1248- } ;
1269+ }
12491270 err. emit ( ) ;
12501271 }
12511272
0 commit comments