Open
Description
Reviewing #87335 (comment) after finding a need for a while-let
loop that provides access to an else pattern I crafted this program:
fn main() {
println!("in");
let mut x: Result<(), &'static str> = Ok(());
'wl: while let _ = match x {
Ok(v) => {
println!("match ok {:?}", v);
x = Err("text");
},
Err(_) => break 'wl,
} {
println!("body");
}
println!("out");
}
The rustc diagnostic output is:
warning: irrefutable `while let` pattern
--> src/main.rs:4:16
|
4 | 'wl: while let _ = match x {
| ________________^
5 | | Ok(v) => {
6 | | println!("match ok {:?}", v);
7 | | x = Err("text");
8 | | },
9 | | Err(_) => break 'wl,
10 | | } {
| |_____^
|
= note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the loop will never exit
= help: consider instead using a `loop { ... }` with a `let` inside it
while the application output is:
in
match ok ()
body
out
Ideally the output should have no diagnostic, because the loop clearly exits.