let join_result = handle.join();
if let Err(err) = join_result {
eprintln!("Error {err:?}");
}
I get a clippy error:
warning: irrefutable `if let` pattern
--> src/read_midi_virtual.rs:70:12
|
70 | if let Err(err) = join_result {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
= note: `#[warn(irrefutable_let_patterns)]` on by default
Yet:
let join_result = handle.join();
match join_result {
Ok(_) => (),
Err(err) => eprintln!("Error read_midi_virtual run: Join error: {err:?}"),
}
The irrefutable_let_patterns warning is specific to if let. There just doesn't happen to be a similar warning for a useless match arm in this case. The problem is the same — your thread is not expected to ever return successfully (presumably it contains a loop {}) so if you get anything from join() at all, it will always be a panic.
As Clippy says, you can replace the if let with a let. Demo program:
use std::thread;
fn main() {
let handle: thread::JoinHandle<_> = thread::spawn(move || loop {
// ...
});
let Err(err) = handle.join();
eprintln!("Error read_midi_virtual run: thread panicked: {err:?}");
}