Skip to content

Commit

Permalink
check_block_with_expected returns the checked type
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Sep 5, 2016
1 parent f54c47d commit 8c6086a
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -2850,8 +2850,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let cond_ty = self.check_expr_has_type(cond_expr, self.tcx.types.bool);

let expected = expected.adjust_for_branches(self);
self.check_block_with_expected(then_blk, expected);
let then_ty = self.node_ty(then_blk.id);
let then_ty = self.check_block_with_expected(then_blk, expected);

let unit = self.tcx.mk_nil();
let (origin, expected, found, result) =
Expand Down Expand Up @@ -3542,8 +3541,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.check_expr_closure(expr, capture, &decl, &body, expected)
}
hir::ExprBlock(ref b) => {
self.check_block_with_expected(&b, expected);
self.node_ty(b.id)
self.check_block_with_expected(&b, expected)
}
hir::ExprCall(ref callee, ref args) => {
self.check_call(expr, &callee, &args[..], expected)
Expand Down Expand Up @@ -3911,8 +3909,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}

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

fn check_block_with_expected(&self,
blk: &'gcx hir::Block,
expected: Expectation<'tcx>) {
expected: Expectation<'tcx>) -> Ty<'tcx> {
let prev = {
let mut fcx_ps = self.ps.borrow_mut();
let unsafety_state = fcx_ps.recurse(blk);
Expand Down Expand Up @@ -3960,13 +3957,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
s_ty.is_never();
any_err = any_err || s_ty.references_error();
}
match blk.expr {
let ty = match blk.expr {
None => if any_err {
self.write_error(blk.id);
self.tcx.types.err
} else if any_diverges {
self.write_ty(blk.id, self.next_diverging_ty_var());
self.next_diverging_ty_var()
} else {
self.write_nil(blk.id);
self.tcx.mk_nil()
},
Some(ref e) => {
if any_diverges && !warned {
Expand All @@ -3988,16 +3985,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};

if any_err {
self.write_error(blk.id);
self.tcx.types.err
} else if any_diverges {
self.write_ty(blk.id, self.next_diverging_ty_var());
self.next_diverging_ty_var()
} else {
self.write_ty(blk.id, ety);
ety
}
}
};
self.write_ty(blk.id, ty);

*self.ps.borrow_mut() = prev;
ty
}

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

0 comments on commit 8c6086a

Please sign in to comment.