From 390b639e59adbb35b491f3080a07ba7b2ed84072 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 11 Jun 2016 18:47:47 +0300 Subject: [PATCH] Move some common code into check_struct_path --- src/librustc_typeck/check/_match.rs | 7 +++---- src/librustc_typeck/check/mod.rs | 17 +++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index e4ed4c1c0b1..e90b32cd5df 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -495,9 +495,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expected: Ty<'tcx>) { // Resolve the path and check the definition for errors. - let def = self.finish_resolving_struct_path(path, pat.id, pat.span); - let variant = if let Some(variant) = self.check_struct_path(def, path, pat.span) { - variant + let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(path, pat.id, + pat.span) { + variant_ty } else { self.write_error(pat.id); for field in fields { @@ -507,7 +507,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; // Type check the path. - let pat_ty = self.instantiate_type_path(def.def_id(), path, pat.id); self.demand_eqtype(pat.span, expected, pat_ty); // Type check subpatterns. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f6f7ee06900..8daa16180a9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3122,10 +3122,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } pub fn check_struct_path(&self, - def: Def, path: &hir::Path, + node_id: ast::NodeId, span: Span) - -> Option> { + -> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> { + let def = self.finish_resolving_struct_path(path, node_id, span); let variant = match def { Def::Err => { self.set_tainted_by_errors(); @@ -3151,7 +3152,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pprust::path_to_string(path)); return None; } - variant + + let ty = self.instantiate_type_path(def.def_id(), path, node_id); + Some((variant.unwrap(), ty)) } fn check_expr_struct(&self, @@ -3161,16 +3164,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { base_expr: &'gcx Option>) { // Find the relevant variant - let def = self.finish_resolving_struct_path(path, expr.id, expr.span); - let variant = if let Some(variant) = self.check_struct_path(def, path, expr.span) { - variant + let (variant, expr_ty) = if let Some(variant_ty) = self.check_struct_path(path, expr.id, + expr.span) { + variant_ty } else { self.check_struct_fields_on_error(expr.id, fields, base_expr); return; }; - let expr_ty = self.instantiate_type_path(def.def_id(), path, expr.id); - self.check_expr_struct_fields(expr_ty, path.span, variant, fields, base_expr.is_none()); if let &Some(ref base_expr) = base_expr {