@@ -1500,7 +1500,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1500
1500
coercion_error. clone ( ) ,
1501
1501
fcx,
1502
1502
parent_id,
1503
- expression. map ( |expr| ( expr, blk_id) ) ,
1503
+ expression,
1504
+ Some ( blk_id) ,
1504
1505
) ;
1505
1506
if !fcx. tcx . features ( ) . unsized_locals {
1506
1507
unsized_return = self . is_return_ty_unsized ( fcx, blk_id) ;
@@ -1514,6 +1515,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1514
1515
coercion_error. clone ( ) ,
1515
1516
fcx,
1516
1517
id,
1518
+ expression,
1517
1519
None ,
1518
1520
) ;
1519
1521
if !fcx. tcx . features ( ) . unsized_locals {
@@ -1564,21 +1566,28 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1564
1566
ty_err : TypeError < ' tcx > ,
1565
1567
fcx : & FnCtxt < ' a , ' tcx > ,
1566
1568
id : hir:: HirId ,
1567
- expression : Option < ( & ' tcx hir:: Expr < ' tcx > , hir:: HirId ) > ,
1569
+ expression : Option < & ' tcx hir:: Expr < ' tcx > > ,
1570
+ blk_id : Option < hir:: HirId > ,
1568
1571
) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
1569
1572
let mut err = fcx. report_mismatched_types ( cause, expected, found, ty_err) ;
1570
1573
1571
1574
let mut pointing_at_return_type = false ;
1572
1575
let mut fn_output = None ;
1573
1576
1577
+ let parent_id = fcx. tcx . hir ( ) . get_parent_node ( id) ;
1578
+ let parent = fcx. tcx . hir ( ) . get ( parent_id) ;
1579
+ if let Some ( expr) = expression
1580
+ && let hir:: Node :: Expr ( hir:: Expr { kind : hir:: ExprKind :: Closure ( _, _, body_id, ..) , .. } ) = parent
1581
+ && !matches ! ( fcx. tcx. hir( ) . get( body_id. hir_id) , hir:: Node :: Expr ( hir:: Expr { kind: hir:: ExprKind :: Block ( ..) , .. } ) )
1582
+ {
1583
+ fcx. suggest_missing_semicolon ( & mut err, expr, expected, true ) ;
1584
+ }
1574
1585
// Verify that this is a tail expression of a function, otherwise the
1575
1586
// label pointing out the cause for the type coercion will be wrong
1576
1587
// as prior return coercions would not be relevant (#57664).
1577
- let parent_id = fcx. tcx . hir ( ) . get_parent_node ( id) ;
1578
- let fn_decl = if let Some ( ( expr, blk_id) ) = expression {
1588
+ let fn_decl = if let ( Some ( expr) , Some ( blk_id) ) = ( expression, blk_id) {
1579
1589
pointing_at_return_type =
1580
1590
fcx. suggest_mismatched_types_on_tail ( & mut err, expr, expected, found, blk_id) ;
1581
- let parent = fcx. tcx . hir ( ) . get ( parent_id) ;
1582
1591
if let ( Some ( cond_expr) , true , false ) = (
1583
1592
fcx. tcx . hir ( ) . get_if_cause ( expr. hir_id ) ,
1584
1593
expected. is_unit ( ) ,
@@ -1607,7 +1616,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1607
1616
} ;
1608
1617
1609
1618
if let Some ( ( fn_decl, can_suggest) ) = fn_decl {
1610
- if expression . is_none ( ) {
1619
+ if blk_id . is_none ( ) {
1611
1620
pointing_at_return_type |= fcx. suggest_missing_return_type (
1612
1621
& mut err,
1613
1622
& fn_decl,
@@ -1625,8 +1634,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1625
1634
let parent_id = fcx. tcx . hir ( ) . get_parent_item ( id) ;
1626
1635
let parent_item = fcx. tcx . hir ( ) . get_by_def_id ( parent_id) ;
1627
1636
1628
- if let ( Some ( ( expr, _ ) ) , Some ( ( fn_decl, _, _) ) ) =
1629
- ( expression, fcx. get_node_fn_decl ( parent_item) )
1637
+ if let ( Some ( expr) , Some ( _ ) , Some ( ( fn_decl, _, _) ) ) =
1638
+ ( expression, blk_id , fcx. get_node_fn_decl ( parent_item) )
1630
1639
{
1631
1640
fcx. suggest_missing_break_or_return_expr (
1632
1641
& mut err,
0 commit comments