Weird `use of moved value` behaviour
⚓ Rust 📅 2026-05-16 👤 surdeus 👁️ 3code from the above playground:
struct NoCopy;
fn this_one_compiles() {
let a = Some(5);
let b = Some(NoCopy);
loop {
if let Some(a) = a && let Some(b) = b {
break (a, b)
}
};
}
fn then_why_doesnt_this_one_compile() {
let a = Some(NoCopy);
let b = Some(NoCopy);
loop {
if let Some(a) = a && let Some(b) = b {
break (a, b)
}
};
}
the first function compiles and shows that rust understands that if let Some(foo) = opt { break foo },
the second function shows that it doesn't.
my guess is that only the last let can consume, but why?
7 posts - 3 participants
🏷️ Rust_feed