@@ -1666,26 +1666,9 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1666
1666
ret_exprs : & Vec < & ' tcx hir:: Expr < ' tcx > > ,
1667
1667
ty : Ty < ' tcx > ,
1668
1668
) {
1669
- let hir = tcx. hir ( ) ;
1670
- let item = hir. get_parent_item ( expr. hir_id ) ;
1671
-
1672
- if let Some ( node) = tcx. opt_hir_node ( item. into ( ) )
1673
- && let Some ( body_id) = node. body_id ( )
1674
- && let Some ( sig) = node. fn_sig ( )
1675
- && let hir:: ExprKind :: Block ( block, _) = hir. body ( body_id) . value . kind
1676
- && !ty. is_never ( )
1677
- {
1678
- for stmt in block. stmts {
1679
- if let hir:: StmtKind :: Local ( local) = stmt. kind {
1680
- if let hir:: PatKind :: Binding ( _, _, _, None ) = local. pat . kind {
1681
- err. span_note (
1682
- stmt. span ,
1683
- "This pattern has a single binding, which might cause issues if the loop doesn't execute. Consider handling the case where the loop might not run." ,
1684
- ) ;
1685
- }
1686
- }
1687
- }
1688
- }
1669
+ let hir:: ExprKind :: Loop ( _, _, _, loop_span) = expr. kind else {
1670
+ return ;
1671
+ } ;
1689
1672
let mut span: MultiSpan = vec ! [ loop_span] . into ( ) ;
1690
1673
span. push_span_label ( loop_span, "this might have zero elements to iterate on" ) ;
1691
1674
const MAXITER : usize = 3 ;
@@ -1717,6 +1700,16 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1717
1700
&& let hir:: ExprKind :: Block ( block, _) = hir. body ( body_id) . value . kind
1718
1701
&& !ty. is_never ( )
1719
1702
{
1703
+ for stmt in block. stmts {
1704
+ if let hir:: StmtKind :: Local ( local) = stmt. kind {
1705
+ if let hir:: PatKind :: Binding ( _, _, _, None ) = local. pat . kind {
1706
+ err. span_note (
1707
+ stmt. span ,
1708
+ "This pattern has a single binding, which might cause issues if the loop doesn't execute. Consider handling the case where the loop might not run." ,
1709
+ ) ;
1710
+ }
1711
+ }
1712
+ }
1720
1713
let indentation = if let None = block. expr
1721
1714
&& let [ .., last] = & block. stmts
1722
1715
{
0 commit comments