Skip to content

Commit 8c6086a

Browse files
committed
check_block_with_expected returns the checked type
1 parent f54c47d commit 8c6086a

File tree

1 file changed

+13
-14
lines changed
  • src/librustc_typeck/check

1 file changed

+13
-14
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,8 +2850,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
28502850
let cond_ty = self.check_expr_has_type(cond_expr, self.tcx.types.bool);
28512851

28522852
let expected = expected.adjust_for_branches(self);
2853-
self.check_block_with_expected(then_blk, expected);
2854-
let then_ty = self.node_ty(then_blk.id);
2853+
let then_ty = self.check_block_with_expected(then_blk, expected);
28552854

28562855
let unit = self.tcx.mk_nil();
28572856
let (origin, expected, found, result) =
@@ -3542,8 +3541,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
35423541
self.check_expr_closure(expr, capture, &decl, &body, expected)
35433542
}
35443543
hir::ExprBlock(ref b) => {
3545-
self.check_block_with_expected(&b, expected);
3546-
self.node_ty(b.id)
3544+
self.check_block_with_expected(&b, expected)
35473545
}
35483546
hir::ExprCall(ref callee, ref args) => {
35493547
self.check_call(expr, &callee, &args[..], expected)
@@ -3911,8 +3909,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39113909
}
39123910

39133911
pub fn check_block_no_value(&self, blk: &'gcx hir::Block) {
3914-
self.check_block_with_expected(blk, ExpectHasType(self.tcx.mk_nil()));
3915-
let blkty = self.node_ty(blk.id);
3912+
let blkty = self.check_block_with_expected(blk, ExpectHasType(self.tcx.mk_nil()));
39163913
if blkty.references_error() {
39173914
self.write_error(blk.id);
39183915
} else {
@@ -3923,7 +3920,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39233920

39243921
fn check_block_with_expected(&self,
39253922
blk: &'gcx hir::Block,
3926-
expected: Expectation<'tcx>) {
3923+
expected: Expectation<'tcx>) -> Ty<'tcx> {
39273924
let prev = {
39283925
let mut fcx_ps = self.ps.borrow_mut();
39293926
let unsafety_state = fcx_ps.recurse(blk);
@@ -3960,13 +3957,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39603957
s_ty.is_never();
39613958
any_err = any_err || s_ty.references_error();
39623959
}
3963-
match blk.expr {
3960+
let ty = match blk.expr {
39643961
None => if any_err {
3965-
self.write_error(blk.id);
3962+
self.tcx.types.err
39663963
} else if any_diverges {
3967-
self.write_ty(blk.id, self.next_diverging_ty_var());
3964+
self.next_diverging_ty_var()
39683965
} else {
3969-
self.write_nil(blk.id);
3966+
self.tcx.mk_nil()
39703967
},
39713968
Some(ref e) => {
39723969
if any_diverges && !warned {
@@ -3988,16 +3985,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39883985
};
39893986

39903987
if any_err {
3991-
self.write_error(blk.id);
3988+
self.tcx.types.err
39923989
} else if any_diverges {
3993-
self.write_ty(blk.id, self.next_diverging_ty_var());
3990+
self.next_diverging_ty_var()
39943991
} else {
3995-
self.write_ty(blk.id, ety);
3992+
ety
39963993
}
39973994
}
39983995
};
3996+
self.write_ty(blk.id, ty);
39993997

40003998
*self.ps.borrow_mut() = prev;
3999+
ty
40014000
}
40024001

40034002
// Instantiates the given path, which must refer to an item with the given

0 commit comments

Comments
 (0)