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