From 144b8cf5db99df4f6132f1ac5b59184f8907965d Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Thu, 18 Aug 2016 22:51:01 +0800 Subject: [PATCH] Factor write_ty out of check_struct_expr --- src/librustc_typeck/check/_match.rs | 1 + src/librustc_typeck/check/mod.rs | 16 +++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index b69afbf8ff03d..838cf36b8853e 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -497,6 +497,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } return; }; + self.write_ty(pat.id, pat_ty); // Type check the path. self.demand_eqtype(pat.span, expected, pat_ty); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 30f4202fccbf0..f70d7c577486c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1711,7 +1711,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.add_obligations_for_parameters(cause, &bounds); let ty_substituted = self.instantiate_type_scheme(path.span, substs, &ty); - self.write_ty(node_id, ty_substituted); self.write_substs(node_id, ty::ItemSubsts { substs: substs }); @@ -3190,12 +3189,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } fn check_struct_fields_on_error(&self, - id: ast::NodeId, fields: &'gcx [hir::Field], - base_expr: &'gcx Option>) -> Ty<'tcx> { - // Make sure to still write the types - // otherwise we might ICE - let ty = self.write_error(id); + base_expr: &'gcx Option>) { for field in fields { self.check_expr(&field.expr); } @@ -3205,7 +3200,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }, None => {} } - ty } pub fn check_struct_path(&self, @@ -3262,7 +3256,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expr.span) { variant_ty } else { - return self.check_struct_fields_on_error(expr.id, fields, base_expr); + self.check_struct_fields_on_error(fields, base_expr); + return self.tcx().types.err; }; self.check_expr_struct_fields(expr_t, path.span, variant, fields, @@ -3286,6 +3281,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } } + self.require_type_is_sized(expr_t, expr.span, traits::StructInitializerSized); expr_t } @@ -3690,9 +3686,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } hir::ExprStruct(ref path, ref fields, ref base_expr) => { let ty = self.check_expr_struct(expr, path, fields, base_expr); - - self.require_type_is_sized(ty, expr.span, traits::StructInitializerSized); - ty + self.write_ty(id, ty) } hir::ExprField(ref base, ref field) => { let ty = self.check_field(expr, lvalue_pref, &base, field);