@@ -3465,7 +3465,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3465
3465
// re-link the regions that EIfEO can erase.
3466
3466
self . demand_eqtype ( span, adt_ty_hint, adt_ty) ;
3467
3467
3468
- let ( substs, adt_kind, kind_name) = match & adt_ty. sty {
3468
+ let ( substs, adt_kind, kind_name) = match & adt_ty. sty {
3469
3469
& ty:: Adt ( adt, substs) => {
3470
3470
( substs, adt. adt_kind ( ) , adt. variant_descr ( ) )
3471
3471
}
@@ -3639,37 +3639,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3639
3639
base_expr : & ' gcx Option < P < hir:: Expr > > ) -> Ty < ' tcx >
3640
3640
{
3641
3641
// Find the relevant variant
3642
- let ( variant, struct_ty ) =
3643
- if let Some ( variant_ty) = self . check_struct_path ( qpath, expr. id ) {
3644
- variant_ty
3645
- } else {
3646
- self . check_struct_fields_on_error ( fields, base_expr) ;
3647
- return self . tcx . types . err ;
3648
- } ;
3642
+ let ( variant, adt_ty ) =
3643
+ if let Some ( variant_ty) = self . check_struct_path ( qpath, expr. id ) {
3644
+ variant_ty
3645
+ } else {
3646
+ self . check_struct_fields_on_error ( fields, base_expr) ;
3647
+ return self . tcx . types . err ;
3648
+ } ;
3649
3649
3650
3650
let path_span = match * qpath {
3651
3651
hir:: QPath :: Resolved ( _, ref path) => path. span ,
3652
3652
hir:: QPath :: TypeRelative ( ref qself, _) => qself. span
3653
3653
} ;
3654
3654
3655
3655
// Prohibit struct expressions when non exhaustive flag is set.
3656
- if let ty:: Adt ( adt, _) = struct_ty. sty {
3657
- if !adt. did . is_local ( ) && adt. is_non_exhaustive ( ) {
3658
- span_err ! ( self . tcx. sess, expr. span, E0639 ,
3659
- "cannot create non-exhaustive {} using struct expression" ,
3660
- adt. variant_descr( ) ) ;
3661
- }
3656
+ let adt = adt_ty. ty_adt_def ( ) . expect ( "`check_struct_path` returned non-ADT type" ) ;
3657
+ if !adt. did . is_local ( ) && adt. is_variant_non_exhaustive ( variant) {
3658
+ span_err ! ( self . tcx. sess, expr. span, E0639 ,
3659
+ "cannot create non-exhaustive {} using struct expression" ,
3660
+ adt. variant_descr( ) ) ;
3662
3661
}
3663
3662
3664
- let error_happened = self . check_expr_struct_fields ( struct_ty , expected, expr. id , path_span,
3663
+ let error_happened = self . check_expr_struct_fields ( adt_ty , expected, expr. id , path_span,
3665
3664
variant, fields, base_expr. is_none ( ) ) ;
3666
3665
if let & Some ( ref base_expr) = base_expr {
3667
3666
// If check_expr_struct_fields hit an error, do not attempt to populate
3668
3667
// the fields with the base_expr. This could cause us to hit errors later
3669
3668
// when certain fields are assumed to exist that in fact do not.
3670
3669
if !error_happened {
3671
- self . check_expr_has_type_or_error ( base_expr, struct_ty ) ;
3672
- match struct_ty . sty {
3670
+ self . check_expr_has_type_or_error ( base_expr, adt_ty ) ;
3671
+ match adt_ty . sty {
3673
3672
ty:: Adt ( adt, substs) if adt. is_struct ( ) => {
3674
3673
let fru_field_types = adt. non_enum_variant ( ) . fields . iter ( ) . map ( |f| {
3675
3674
self . normalize_associated_types_in ( expr. span , & f. ty ( self . tcx , substs) )
@@ -3687,8 +3686,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3687
3686
}
3688
3687
}
3689
3688
}
3690
- self . require_type_is_sized ( struct_ty , expr. span , traits:: StructInitializerSized ) ;
3691
- struct_ty
3689
+ self . require_type_is_sized ( adt_ty , expr. span , traits:: StructInitializerSized ) ;
3690
+ adt_ty
3692
3691
}
3693
3692
3694
3693
0 commit comments