@@ -3480,6 +3480,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3480
3480
coerce. coerce_forced_unit ( self , & else_cause, & mut |err| {
3481
3481
if let Some ( ( sp, msg) ) = & ret_reason {
3482
3482
err. span_label ( * sp, msg. as_str ( ) ) ;
3483
+ } else if let ExprKind :: Block ( block, _) = & then_expr. node {
3484
+ if let Some ( expr) = & block. expr {
3485
+ err. span_label ( expr. span , "found here" . to_string ( ) ) ;
3486
+ }
3483
3487
}
3484
3488
err. note ( "`if` expressions without `else` evaluate to `()`" ) ;
3485
3489
err. help ( "consider adding an `else` block that evaluates to the expected type" ) ;
@@ -3498,11 +3502,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3498
3502
}
3499
3503
3500
3504
fn maybe_get_coercion_reason ( & self , hir_id : hir:: HirId , sp : Span ) -> Option < ( Span , String ) > {
3501
- if let Node :: Block ( block) = self . tcx . hir ( ) . get_by_hir_id (
3502
- self . tcx . hir ( ) . get_parent_node_by_hir_id (
3503
- self . tcx . hir ( ) . get_parent_node_by_hir_id ( hir_id) ,
3504
- ) ,
3505
- ) {
3505
+ let node = self . tcx . hir ( ) . get_by_hir_id ( self . tcx . hir ( ) . get_parent_node_by_hir_id (
3506
+ self . tcx . hir ( ) . get_parent_node_by_hir_id ( hir_id) ,
3507
+ ) ) ;
3508
+ if let Node :: Block ( block) = node {
3506
3509
// check that the body's parent is an fn
3507
3510
let parent = self . tcx . hir ( ) . get_by_hir_id (
3508
3511
self . tcx . hir ( ) . get_parent_node_by_hir_id (
@@ -3521,6 +3524,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3521
3524
}
3522
3525
}
3523
3526
}
3527
+ if let Node :: Local ( hir:: Local {
3528
+ ty : Some ( _) , pat, ..
3529
+ } ) = node {
3530
+ return Some ( ( pat. span , "expected because of this assignment" . to_string ( ) ) ) ;
3531
+ }
3524
3532
None
3525
3533
}
3526
3534
0 commit comments