Skip to content

Commit 4fe62be

Browse files
committed
Address irrefutable while let diagnostic review
1 parent d2bb772 commit 4fe62be

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,11 +1895,11 @@ impl<'tcx> CoerceMany<'tcx> {
18951895

18961896
err.note(format!("{loop_type} evaluate to unit type `()`"));
18971897
if loop_src == hir::LoopSource::While
1898-
&& let Some(pat) = irrefutable_while_let_pattern(block)
1898+
&& let Some(pat) = irrefutable_if_let_expr(block)
18991899
{
19001900
err.span_note(
19011901
pat.span,
1902-
"this pattern always matches, so the loop condition never fails",
1902+
"this pattern always matches, consider using `loop` instead",
19031903
);
19041904
}
19051905
}
@@ -2134,7 +2134,7 @@ impl<'tcx> CoerceMany<'tcx> {
21342134
}
21352135
}
21362136

2137-
fn irrefutable_while_let_pattern<'hir>(block: &hir::Block<'hir>) -> Option<&'hir hir::Pat<'hir>> {
2137+
fn irrefutable_if_let_expr<'hir>(block: &hir::Block<'hir>) -> Option<&'hir hir::Pat<'hir>> {
21382138
let hir::ExprKind::If(cond, _, _) = block.expr?.kind else {
21392139
return None;
21402140
};

tests/ui/coercion/coerce-loop-issue-122561.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ LL | | }
182182
| |_____^ expected `bool`, found `()`
183183
|
184184
= note: `while` loops evaluate to unit type `()`
185-
note: this pattern always matches, so the loop condition never fails
185+
note: this pattern always matches, consider using `loop` instead
186186
--> $DIR/coerce-loop-issue-122561.rs:73:15
187187
|
188188
LL | while let x = false {
@@ -207,7 +207,7 @@ LL | | }
207207
| |_____^ expected `bool`, found `()`
208208
|
209209
= note: `while` loops evaluate to unit type `()`
210-
note: this pattern always matches, so the loop condition never fails
210+
note: this pattern always matches, consider using `loop` instead
211211
--> $DIR/coerce-loop-issue-122561.rs:82:15
212212
|
213213
LL | while let (x, _) = (false, true) {

0 commit comments

Comments
 (0)