about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-06-11 18:47:47 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-07-08 12:42:57 +0300
commit390b639e59adbb35b491f3080a07ba7b2ed84072 (patch)
tree75158fb1bc22b740354a508b62865507cb763fc5
parent2859f8bf3984c5871df0ee7395ec732e4a79759f (diff)
downloadrust-390b639e59adbb35b491f3080a07ba7b2ed84072.tar.gz
rust-390b639e59adbb35b491f3080a07ba7b2ed84072.zip
Move some common code into check_struct_path
-rw-r--r--src/librustc_typeck/check/_match.rs7
-rw-r--r--src/librustc_typeck/check/mod.rs17
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<ty::VariantDef<'tcx>> {
+                         -> 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<P<hir::Expr>>)
     {
         // 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 {