@@ -2850,8 +2850,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2850
2850
let cond_ty = self . check_expr_has_type ( cond_expr, self . tcx . types . bool ) ;
2851
2851
2852
2852
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) ;
2855
2854
2856
2855
let unit = self . tcx . mk_nil ( ) ;
2857
2856
let ( origin, expected, found, result) =
@@ -3542,8 +3541,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3542
3541
self . check_expr_closure ( expr, capture, & decl, & body, expected)
3543
3542
}
3544
3543
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)
3547
3545
}
3548
3546
hir:: ExprCall ( ref callee, ref args) => {
3549
3547
self . check_call ( expr, & callee, & args[ ..] , expected)
@@ -3911,8 +3909,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3911
3909
}
3912
3910
3913
3911
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 ( ) ) ) ;
3916
3913
if blkty. references_error ( ) {
3917
3914
self . write_error ( blk. id ) ;
3918
3915
} else {
@@ -3923,7 +3920,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3923
3920
3924
3921
fn check_block_with_expected ( & self ,
3925
3922
blk : & ' gcx hir:: Block ,
3926
- expected : Expectation < ' tcx > ) {
3923
+ expected : Expectation < ' tcx > ) -> Ty < ' tcx > {
3927
3924
let prev = {
3928
3925
let mut fcx_ps = self . ps . borrow_mut ( ) ;
3929
3926
let unsafety_state = fcx_ps. recurse ( blk) ;
@@ -3960,13 +3957,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3960
3957
s_ty. is_never ( ) ;
3961
3958
any_err = any_err || s_ty. references_error ( ) ;
3962
3959
}
3963
- match blk. expr {
3960
+ let ty = match blk. expr {
3964
3961
None => if any_err {
3965
- self . write_error ( blk . id ) ;
3962
+ self . tcx . types . err
3966
3963
} else if any_diverges {
3967
- self . write_ty ( blk . id , self . next_diverging_ty_var ( ) ) ;
3964
+ self . next_diverging_ty_var ( )
3968
3965
} else {
3969
- self . write_nil ( blk . id ) ;
3966
+ self . tcx . mk_nil ( )
3970
3967
} ,
3971
3968
Some ( ref e) => {
3972
3969
if any_diverges && !warned {
@@ -3988,16 +3985,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3988
3985
} ;
3989
3986
3990
3987
if any_err {
3991
- self . write_error ( blk . id ) ;
3988
+ self . tcx . types . err
3992
3989
} else if any_diverges {
3993
- self . write_ty ( blk . id , self . next_diverging_ty_var ( ) ) ;
3990
+ self . next_diverging_ty_var ( )
3994
3991
} else {
3995
- self . write_ty ( blk . id , ety) ;
3992
+ ety
3996
3993
}
3997
3994
}
3998
3995
} ;
3996
+ self . write_ty ( blk. id , ty) ;
3999
3997
4000
3998
* self . ps . borrow_mut ( ) = prev;
3999
+ ty
4001
4000
}
4002
4001
4003
4002
// Instantiates the given path, which must refer to an item with the given
0 commit comments