Skip to content

Commit 819c4f2

Browse files
committed
typeck/expr.rs: move some check_return_expr here.
1 parent 18edf3e commit 819c4f2

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/librustc_typeck/check/expr.rs

+17
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
633633
self.tcx.types.never
634634
}
635635

636+
pub(super) fn check_return_expr(&self, return_expr: &'tcx hir::Expr) {
637+
let ret_coercion =
638+
self.ret_coercion
639+
.as_ref()
640+
.unwrap_or_else(|| span_bug!(return_expr.span,
641+
"check_return_expr called outside fn body"));
642+
643+
let ret_ty = ret_coercion.borrow().expected_ty();
644+
let return_expr_ty = self.check_expr_with_hint(return_expr, ret_ty.clone());
645+
ret_coercion.borrow_mut()
646+
.coerce(self,
647+
&self.cause(return_expr.span,
648+
ObligationCauseCode::ReturnType(return_expr.hir_id)),
649+
return_expr,
650+
return_expr_ty);
651+
}
652+
636653
/// Type check assignment expression `expr` of form `lhs = rhs`.
637654
/// The expected type is `()` and is passsed to the function for the purposes of diagnostics.
638655
fn check_expr_assign(

src/librustc_typeck/check/mod.rs

-17
Original file line numberDiff line numberDiff line change
@@ -3312,23 +3312,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33123312
expected)
33133313
}
33143314

3315-
fn check_return_expr(&self, return_expr: &'tcx hir::Expr) {
3316-
let ret_coercion =
3317-
self.ret_coercion
3318-
.as_ref()
3319-
.unwrap_or_else(|| span_bug!(return_expr.span,
3320-
"check_return_expr called outside fn body"));
3321-
3322-
let ret_ty = ret_coercion.borrow().expected_ty();
3323-
let return_expr_ty = self.check_expr_with_hint(return_expr, ret_ty.clone());
3324-
ret_coercion.borrow_mut()
3325-
.coerce(self,
3326-
&self.cause(return_expr.span,
3327-
ObligationCauseCode::ReturnType(return_expr.hir_id)),
3328-
return_expr,
3329-
return_expr_ty);
3330-
}
3331-
33323315
// Check field access expressions
33333316
fn check_field(
33343317
&self,

0 commit comments

Comments
 (0)