Skip to content

Commit 57393b7

Browse files
committed
Label irrefutable while let pattern diagnostic
1 parent 4fe62be commit 57393b7

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ impl<'tcx> CoerceMany<'tcx> {
18971897
if loop_src == hir::LoopSource::While
18981898
&& let Some(pat) = irrefutable_if_let_expr(block)
18991899
{
1900-
err.span_note(
1900+
err.span_label(
19011901
pat.span,
19021902
"this pattern always matches, consider using `loop` instead",
19031903
);

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ error[E0308]: mismatched types
173173
|
174174
LL | fn while_let_binding() -> bool {
175175
| ---- expected `bool` because of return type
176-
LL | / while let x = false {
176+
LL | while let x = false {
177+
| ^ - this pattern always matches, consider using `loop` instead
178+
| _____|
179+
| |
177180
LL | |
178181
LL | | if x {
179182
LL | | return true;
@@ -182,11 +185,6 @@ LL | | }
182185
| |_____^ expected `bool`, found `()`
183186
|
184187
= note: `while` loops evaluate to unit type `()`
185-
note: this pattern always matches, consider using `loop` instead
186-
--> $DIR/coerce-loop-issue-122561.rs:73:15
187-
|
188-
LL | while let x = false {
189-
| ^
190188
help: consider returning a value here
191189
|
192190
LL ~ }
@@ -198,7 +196,10 @@ error[E0308]: mismatched types
198196
|
199197
LL | fn while_let_tuple() -> bool {
200198
| ---- expected `bool` because of return type
201-
LL | / while let (x, _) = (false, true) {
199+
LL | while let (x, _) = (false, true) {
200+
| ^ ------ this pattern always matches, consider using `loop` instead
201+
| _____|
202+
| |
202203
LL | |
203204
LL | | if x {
204205
LL | | return true;
@@ -207,11 +208,6 @@ LL | | }
207208
| |_____^ expected `bool`, found `()`
208209
|
209210
= note: `while` loops evaluate to unit type `()`
210-
note: this pattern always matches, consider using `loop` instead
211-
--> $DIR/coerce-loop-issue-122561.rs:82:15
212-
|
213-
LL | while let (x, _) = (false, true) {
214-
| ^^^^^^
215211
help: consider returning a value here
216212
|
217213
LL ~ }

0 commit comments

Comments
 (0)