about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-15 02:25:37 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-06-15 02:25:37 +0200
commitfe004da37aabccc596b818a79beaee3e08508ccc (patch)
tree149443194850de765d44473f1b1b0c1e1692dba2 /src
parent046cd903c5b700782d08bbd54ff7c88bebbf24d9 (diff)
downloadrust-fe004da37aabccc596b818a79beaee3e08508ccc.tar.gz
rust-fe004da37aabccc596b818a79beaee3e08508ccc.zip
typeck/expr.rs: extract out check_expr_cast.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/expr.rs55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs
index 4911486a70d..70420f4ee5a 100644
--- a/src/librustc_typeck/check/expr.rs
+++ b/src/librustc_typeck/check/expr.rs
@@ -114,29 +114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 self.check_method_call(expr, segment, span, args, expected, needs)
             }
             ExprKind::Cast(ref e, ref t) => {
-                // Find the type of `e`. Supply hints based on the type we are casting to,
-                // if appropriate.
-                let t_cast = self.to_ty_saving_user_provided_ty(t);
-                let t_cast = self.resolve_vars_if_possible(&t_cast);
-                let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast));
-                let t_cast = self.resolve_vars_if_possible(&t_cast);
-
-                // Eagerly check for some obvious errors.
-                if t_expr.references_error() || t_cast.references_error() {
-                    tcx.types.err
-                } else {
-                    // Defer other checks until we're done type checking.
-                    let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
-                    match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
-                        Ok(cast_check) => {
-                            deferred_cast_checks.push(cast_check);
-                            t_cast
-                        }
-                        Err(ErrorReported) => {
-                            tcx.types.err
-                        }
-                    }
-                }
+                self.check_expr_cast(e, t, expr)
             }
             ExprKind::Type(ref e, ref t) => {
                 let ty = self.to_ty_saving_user_provided_ty(&t);
@@ -806,4 +784,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         }
         ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit())
     }
+
+    fn check_expr_cast(
+        &self,
+        e: &'tcx hir::Expr,
+        t: &'tcx hir::Ty,
+        expr: &'tcx hir::Expr,
+    ) -> Ty<'tcx> {
+        // Find the type of `e`. Supply hints based on the type we are casting to,
+        // if appropriate.
+        let t_cast = self.to_ty_saving_user_provided_ty(t);
+        let t_cast = self.resolve_vars_if_possible(&t_cast);
+        let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast));
+        let t_cast = self.resolve_vars_if_possible(&t_cast);
+
+        // Eagerly check for some obvious errors.
+        if t_expr.references_error() || t_cast.references_error() {
+            self.tcx.types.err
+        } else {
+            // Defer other checks until we're done type checking.
+            let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
+            match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
+                Ok(cast_check) => {
+                    deferred_cast_checks.push(cast_check);
+                    t_cast
+                }
+                Err(ErrorReported) => {
+                    self.tcx.types.err
+                }
+            }
+        }
+    }
 }