Using if let Err(_) on a Thread::JoinHandle::result

⚓ Rust    📅 2025-08-28    👤 surdeus    👁️ 2      

surdeus

I have a JoinHandle from:

let handle: thread::JoinHandle<_> = thread::spawn(move || {
    blah blah blah
}

When I try to join it:

        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:?}"),
        }

has no warnings.

I do not understand.

I am using edition 2024 if it matters

5 posts - 3 participants

Read full topic

🏷️ Rust_feed