@@ -1500,7 +1500,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15001500 coercion_error. clone ( ) ,
15011501 fcx,
15021502 parent_id,
1503- expression. map ( |expr| ( expr, blk_id) ) ,
1503+ expression,
1504+ Some ( blk_id) ,
15041505 ) ;
15051506 if !fcx. tcx . features ( ) . unsized_locals {
15061507 unsized_return = self . is_return_ty_unsized ( fcx, blk_id) ;
@@ -1514,6 +1515,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15141515 coercion_error. clone ( ) ,
15151516 fcx,
15161517 id,
1518+ expression,
15171519 None ,
15181520 ) ;
15191521 if !fcx. tcx . features ( ) . unsized_locals {
@@ -1564,21 +1566,30 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15641566 ty_err : TypeError < ' tcx > ,
15651567 fcx : & FnCtxt < ' a , ' tcx > ,
15661568 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 > ,
15681571 ) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
15691572 let mut err = fcx. report_mismatched_types ( cause, expected, found, ty_err) ;
15701573
15711574 let mut pointing_at_return_type = false ;
15721575 let mut fn_output = None ;
15731576
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+ && expr. can_have_side_effects ( )
1583+ && !in_external_macro ( fcx. tcx . sess , expr. span )
1584+ {
1585+ fcx. suggest_missing_semicolon ( & mut err, expr, expected, true ) ;
1586+ }
15741587 // Verify that this is a tail expression of a function, otherwise the
15751588 // label pointing out the cause for the type coercion will be wrong
15761589 // 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 {
1590+ let fn_decl = if let ( Some ( expr) , Some ( blk_id) ) = ( expression, blk_id) {
15791591 pointing_at_return_type =
15801592 fcx. suggest_mismatched_types_on_tail ( & mut err, expr, expected, found, blk_id) ;
1581- let parent = fcx. tcx . hir ( ) . get ( parent_id) ;
15821593 if let ( Some ( cond_expr) , true , false ) = (
15831594 fcx. tcx . hir ( ) . get_if_cause ( expr. hir_id ) ,
15841595 expected. is_unit ( ) ,
@@ -1607,7 +1618,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16071618 } ;
16081619
16091620 if let Some ( ( fn_decl, can_suggest) ) = fn_decl {
1610- if expression . is_none ( ) {
1621+ if blk_id . is_none ( ) {
16111622 pointing_at_return_type |= fcx. suggest_missing_return_type (
16121623 & mut err,
16131624 & fn_decl,
@@ -1625,8 +1636,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16251636 let parent_id = fcx. tcx . hir ( ) . get_parent_item ( id) ;
16261637 let parent_item = fcx. tcx . hir ( ) . get_by_def_id ( parent_id) ;
16271638
1628- if let ( Some ( ( expr, _ ) ) , Some ( ( fn_decl, _, _) ) ) =
1629- ( expression, fcx. get_node_fn_decl ( parent_item) )
1639+ if let ( Some ( expr) , Some ( _ ) , Some ( ( fn_decl, _, _) ) ) =
1640+ ( expression, blk_id , fcx. get_node_fn_decl ( parent_item) )
16301641 {
16311642 fcx. suggest_missing_break_or_return_expr (
16321643 & mut err,
0 commit comments