@@ -3465,7 +3465,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
34653465 // re-link the regions that EIfEO can erase.
34663466 self . demand_eqtype ( span, adt_ty_hint, adt_ty) ;
34673467
3468- let ( substs, adt_kind, kind_name) = match & adt_ty. sty {
3468+ let ( substs, adt_kind, kind_name) = match & adt_ty. sty {
34693469 & ty:: Adt ( adt, substs) => {
34703470 ( substs, adt. adt_kind ( ) , adt. variant_descr ( ) )
34713471 }
@@ -3639,37 +3639,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
36393639 base_expr : & ' gcx Option < P < hir:: Expr > > ) -> Ty < ' tcx >
36403640 {
36413641 // 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+ } ;
36493649
36503650 let path_span = match * qpath {
36513651 hir:: QPath :: Resolved ( _, ref path) => path. span ,
36523652 hir:: QPath :: TypeRelative ( ref qself, _) => qself. span
36533653 } ;
36543654
36553655 // 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( ) ) ;
36623661 }
36633662
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,
36653664 variant, fields, base_expr. is_none ( ) ) ;
36663665 if let & Some ( ref base_expr) = base_expr {
36673666 // If check_expr_struct_fields hit an error, do not attempt to populate
36683667 // the fields with the base_expr. This could cause us to hit errors later
36693668 // when certain fields are assumed to exist that in fact do not.
36703669 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 {
36733672 ty:: Adt ( adt, substs) if adt. is_struct ( ) => {
36743673 let fru_field_types = adt. non_enum_variant ( ) . fields . iter ( ) . map ( |f| {
36753674 self . normalize_associated_types_in ( expr. span , & f. ty ( self . tcx , substs) )
@@ -3687,8 +3686,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
36873686 }
36883687 }
36893688 }
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
36923691 }
36933692
36943693
0 commit comments