about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-15 02:39:23 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-06-15 02:39:23 +0200
commitbb934880f0155096a6bce813ae6e6afd9fd110b9 (patch)
treeaf9f4d17e7bc4ffb107da3d327a3e683607e35f1
parent82cac1505cb87ccb594aa68b4ad3f27f67720ecf (diff)
downloadrust-bb934880f0155096a6bce813ae6e6afd9fd110b9.tar.gz
rust-bb934880f0155096a6bce813ae6e6afd9fd110b9.zip
typeck/expr.rs: extract out check_expr_tuple.
-rw-r--r--src/librustc_typeck/check/expr.rs65
1 files changed, 37 insertions, 28 deletions
diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs
index 5b3ad729ea8..8f93e3837fa 100644
--- a/src/librustc_typeck/check/expr.rs
+++ b/src/librustc_typeck/check/expr.rs
@@ -131,34 +131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 self.check_expr_repeat(element, count, expected, expr)
             }
             ExprKind::Tup(ref elts) => {
-                let flds = expected.only_has_type(self).and_then(|ty| {
-                    let ty = self.resolve_type_vars_with_obligations(ty);
-                    match ty.sty {
-                        ty::Tuple(ref flds) => Some(&flds[..]),
-                        _ => None
-                    }
-                });
-
-                let elt_ts_iter = elts.iter().enumerate().map(|(i, e)| {
-                    let t = match flds {
-                        Some(ref fs) if i < fs.len() => {
-                            let ety = fs[i].expect_ty();
-                            self.check_expr_coercable_to_type(&e, ety);
-                            ety
-                        }
-                        _ => {
-                            self.check_expr_with_expectation(&e, NoExpectation)
-                        }
-                    };
-                    t
-                });
-                let tuple = tcx.mk_tup(elt_ts_iter);
-                if tuple.references_error() {
-                    tcx.types.err
-                } else {
-                    self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
-                    tuple
-                }
+                self.check_expr_tuple(elts, expected, expr)
             }
             ExprKind::Struct(ref qpath, ref fields, ref base_expr) => {
                 self.check_expr_struct(expr, expected, qpath, fields, base_expr)
@@ -835,4 +808,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             tcx.types.err
         }
     }
+
+    fn check_expr_tuple(
+        &self,
+        elts: &'tcx [hir::Expr],
+        expected: Expectation<'tcx>,
+        expr: &'tcx hir::Expr,
+    ) -> Ty<'tcx> {
+        let flds = expected.only_has_type(self).and_then(|ty| {
+            let ty = self.resolve_type_vars_with_obligations(ty);
+            match ty.sty {
+                ty::Tuple(ref flds) => Some(&flds[..]),
+                _ => None
+            }
+        });
+
+        let elt_ts_iter = elts.iter().enumerate().map(|(i, e)| {
+            let t = match flds {
+                Some(ref fs) if i < fs.len() => {
+                    let ety = fs[i].expect_ty();
+                    self.check_expr_coercable_to_type(&e, ety);
+                    ety
+                }
+                _ => {
+                    self.check_expr_with_expectation(&e, NoExpectation)
+                }
+            };
+            t
+        });
+        let tuple = self.tcx.mk_tup(elt_ts_iter);
+        if tuple.references_error() {
+            self.tcx.types.err
+        } else {
+            self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
+            tuple
+        }
+    }
 }