@@ -3125,11 +3125,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3125
3125
3126
3126
let adt_ty_hint =
3127
3127
self . expected_inputs_for_expected_output ( span, expected, adt_ty, & [ adt_ty] )
3128
- . get ( 0 ) . cloned ( ) . unwrap_or ( adt_ty) ;
3128
+ . get ( 0 ) . cloned ( ) . unwrap_or ( adt_ty) ;
3129
+ // re-link the regions that EIfEO can erase.
3130
+ self . demand_eqtype ( span, adt_ty_hint, adt_ty) ;
3129
3131
3130
- let ( substs, hint_substs , adt_kind, kind_name) = match ( & adt_ty. sty , & adt_ty_hint . sty ) {
3131
- ( & ty:: TyAdt ( adt, substs) , & ty :: TyAdt ( _ , hint_substs ) ) => {
3132
- ( substs, hint_substs , adt. adt_kind ( ) , adt. variant_descr ( ) )
3132
+ let ( substs, adt_kind, kind_name) = match & adt_ty. sty {
3133
+ & ty:: TyAdt ( adt, substs) => {
3134
+ ( substs, adt. adt_kind ( ) , adt. variant_descr ( ) )
3133
3135
}
3134
3136
_ => span_bug ! ( span, "non-ADT passed to check_expr_struct_fields" )
3135
3137
} ;
@@ -3145,14 +3147,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3145
3147
3146
3148
// Typecheck each field.
3147
3149
for field in ast_fields {
3148
- let final_field_type;
3149
- let field_type_hint;
3150
-
3151
3150
let ident = tcx. adjust ( field. name . node , variant. did , self . body_id ) . 0 ;
3152
- if let Some ( v_field) = remaining_fields. remove ( & ident) {
3153
- final_field_type = self . field_ty ( field. span , v_field, substs) ;
3154
- field_type_hint = self . field_ty ( field. span , v_field, hint_substs) ;
3155
-
3151
+ let field_type = if let Some ( v_field) = remaining_fields. remove ( & ident) {
3156
3152
seen_fields. insert ( field. name . node , field. span ) ;
3157
3153
3158
3154
// we don't look at stability attributes on
@@ -3161,10 +3157,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3161
3157
if adt_kind != ty:: AdtKind :: Enum {
3162
3158
tcx. check_stability ( v_field. did , expr_id, field. span ) ;
3163
3159
}
3160
+
3161
+ self . field_ty ( field. span , v_field, substs)
3164
3162
} else {
3165
3163
error_happened = true ;
3166
- final_field_type = tcx. types . err ;
3167
- field_type_hint = tcx. types . err ;
3168
3164
if let Some ( _) = variant. find_field_named ( field. name . node ) {
3169
3165
let mut err = struct_span_err ! ( self . tcx. sess,
3170
3166
field. name. span,
@@ -3182,12 +3178,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3182
3178
} else {
3183
3179
self . report_unknown_field ( adt_ty, variant, field, ast_fields, kind_name) ;
3184
3180
}
3185
- }
3181
+
3182
+ tcx. types . err
3183
+ } ;
3186
3184
3187
3185
// Make sure to give a type to the field even if there's
3188
3186
// an error, so we can continue typechecking
3189
- let ty = self . check_expr_with_hint ( & field. expr , field_type_hint) ;
3190
- self . demand_coerce ( & field. expr , ty, final_field_type) ;
3187
+ self . check_expr_coercable_to_type ( & field. expr , field_type) ;
3191
3188
}
3192
3189
3193
3190
// Make sure the programmer specified correct number of fields.
0 commit comments