@@ -3480,6 +3480,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
34803480 coerce. coerce_forced_unit ( self , & else_cause, & mut |err| {
34813481 if let Some ( ( sp, msg) ) = & ret_reason {
34823482 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+ }
34833487 }
34843488 err. note ( "`if` expressions without `else` evaluate to `()`" ) ;
34853489 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> {
34983502 }
34993503
35003504 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 {
35063509 // check that the body's parent is an fn
35073510 let parent = self . tcx . hir ( ) . get_by_hir_id (
35083511 self . tcx . hir ( ) . get_parent_node_by_hir_id (
@@ -3521,6 +3524,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
35213524 }
35223525 }
35233526 }
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+ }
35243532 None
35253533 }
35263534
0 commit comments