]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/expr.rs
typeck/expr.rs: move some check_return_expr here.
[rust.git] / src / librustc_typeck / check / expr.rs
index da90988814ba2c2ff228ed5ff808b01a179a70bc..7aa47a1a3a1fb60a7ca366121fc25dc61f949122 100644 (file)
@@ -633,6 +633,23 @@ fn check_expr_return(
         self.tcx.types.never
     }
 
+    pub(super) fn check_return_expr(&self, return_expr: &'tcx hir::Expr) {
+        let ret_coercion =
+            self.ret_coercion
+                .as_ref()
+                .unwrap_or_else(|| span_bug!(return_expr.span,
+                                             "check_return_expr called outside fn body"));
+
+        let ret_ty = ret_coercion.borrow().expected_ty();
+        let return_expr_ty = self.check_expr_with_hint(return_expr, ret_ty.clone());
+        ret_coercion.borrow_mut()
+                    .coerce(self,
+                            &self.cause(return_expr.span,
+                                        ObligationCauseCode::ReturnType(return_expr.hir_id)),
+                            return_expr,
+                            return_expr_ty);
+    }
+
     /// Type check assignment expression `expr` of form `lhs = rhs`.
     /// The expected type is `()` and is passsed to the function for the purposes of diagnostics.
     fn check_expr_assign(