@@ -3418,7 +3418,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3418
3418
substitutions : subst:: Substs < ' tcx > ,
3419
3419
field_types : & [ ty:: field_ty ] ,
3420
3420
ast_fields : & [ ast:: Field ] ,
3421
- check_completeness : bool ) {
3421
+ check_completeness : bool ,
3422
+ enum_id_opt : Option < ast:: DefId > ) {
3422
3423
let tcx = fcx. ccx . tcx ;
3423
3424
3424
3425
let mut class_field_map = FnvHashMap :: new ( ) ;
@@ -3437,13 +3438,24 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3437
3438
match pair {
3438
3439
None => {
3439
3440
fcx. type_error_message (
3440
- field. ident . span ,
3441
- |actual| {
3442
- format ! ( "structure `{}` has no field named `{}`" ,
3443
- actual, token:: get_ident( field. ident. node) )
3444
- } ,
3445
- struct_ty,
3446
- None ) ;
3441
+ field. ident . span ,
3442
+ |actual| match enum_id_opt {
3443
+ Some ( enum_id) => {
3444
+ let variant_type = ty:: enum_variant_with_id ( tcx,
3445
+ enum_id,
3446
+ class_id) ;
3447
+ format ! ( "struct variant `{}::{}` has no field named `{}`" ,
3448
+ actual, variant_type. name. as_str( ) ,
3449
+ token:: get_ident( field. ident. node) )
3450
+ }
3451
+ None => {
3452
+ format ! ( "structure `{}` has no field named `{}`" ,
3453
+ actual,
3454
+ token:: get_ident( field. ident. node) )
3455
+ }
3456
+ } ,
3457
+ struct_ty,
3458
+ None ) ;
3447
3459
error_happened = true ;
3448
3460
}
3449
3461
Some ( ( _, true ) ) => {
@@ -3524,7 +3536,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3524
3536
struct_substs,
3525
3537
class_fields[ ] ,
3526
3538
fields,
3527
- base_expr. is_none ( ) ) ;
3539
+ base_expr. is_none ( ) ,
3540
+ None ) ;
3528
3541
if ty:: type_is_error ( fcx. node_ty ( id) ) {
3529
3542
struct_type = ty:: mk_err ( ) ;
3530
3543
}
@@ -3566,7 +3579,8 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3566
3579
substitutions,
3567
3580
variant_fields[ ] ,
3568
3581
fields,
3569
- true ) ;
3582
+ true ,
3583
+ Some ( enum_id) ) ;
3570
3584
fcx. write_ty ( id, enum_type) ;
3571
3585
}
3572
3586
0 commit comments