Skip to content

Commit e282c43

Browse files
author
yossydev
committed
fix
1 parent cd4f745 commit e282c43

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -1666,26 +1666,9 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16661666
ret_exprs: &Vec<&'tcx hir::Expr<'tcx>>,
16671667
ty: Ty<'tcx>,
16681668
) {
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+
};
16891672
let mut span: MultiSpan = vec![loop_span].into();
16901673
span.push_span_label(loop_span, "this might have zero elements to iterate on");
16911674
const MAXITER: usize = 3;
@@ -1717,6 +1700,16 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17171700
&& let hir::ExprKind::Block(block, _) = hir.body(body_id).value.kind
17181701
&& !ty.is_never()
17191702
{
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+
}
17201713
let indentation = if let None = block.expr
17211714
&& let [.., last] = &block.stmts
17221715
{

0 commit comments

Comments
 (0)