Address irrefutable while let diagnostic review
diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index d8881de..9a20d47 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs
@@ -1895,11 +1895,11 @@ pub(crate) fn coerce_inner<'a>( err.note(format!("{loop_type} evaluate to unit type `()`")); if loop_src == hir::LoopSource::While - && let Some(pat) = irrefutable_while_let_pattern(block) + && let Some(pat) = irrefutable_if_let_expr(block) { err.span_note( pat.span, - "this pattern always matches, so the loop condition never fails", + "this pattern always matches, consider using `loop` instead", ); } } @@ -2134,7 +2134,7 @@ pub(crate) fn complete<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Ty<'tcx> { } } -fn irrefutable_while_let_pattern<'hir>(block: &hir::Block<'hir>) -> Option<&'hir hir::Pat<'hir>> { +fn irrefutable_if_let_expr<'hir>(block: &hir::Block<'hir>) -> Option<&'hir hir::Pat<'hir>> { let hir::ExprKind::If(cond, _, _) = block.expr?.kind else { return None; };
diff --git a/tests/ui/coercion/coerce-loop-issue-122561.stderr b/tests/ui/coercion/coerce-loop-issue-122561.stderr index ef7a304..1051823 100644 --- a/tests/ui/coercion/coerce-loop-issue-122561.stderr +++ b/tests/ui/coercion/coerce-loop-issue-122561.stderr
@@ -182,7 +182,7 @@ | |_____^ expected `bool`, found `()` | = note: `while` loops evaluate to unit type `()` -note: this pattern always matches, so the loop condition never fails +note: this pattern always matches, consider using `loop` instead --> $DIR/coerce-loop-issue-122561.rs:73:15 | LL | while let x = false { @@ -207,7 +207,7 @@ | |_____^ expected `bool`, found `()` | = note: `while` loops evaluate to unit type `()` -note: this pattern always matches, so the loop condition never fails +note: this pattern always matches, consider using `loop` instead --> $DIR/coerce-loop-issue-122561.rs:82:15 | LL | while let (x, _) = (false, true) {