Skip to content

Commit

Permalink
typeck/expr.rs: move some check_return_expr here.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jun 15, 2019
1 parent 18edf3e commit 819c4f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 17 additions & 0 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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(
Expand Down
17 changes: 0 additions & 17 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3312,23 +3312,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected)
}

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);
}

// Check field access expressions
fn check_field(
&self,
Expand Down

0 comments on commit 819c4f2

Please sign in to comment.