Consider two semantically equivalent pieces of code:
let x = Mutex::new(0);
if *x.lock().unwrap() == 0 {
*x.lock().unwrap() = 1;
}
let x = Mutex::new(0);
if let 0 = *x.lock().unwrap() {
*x.lock().unwrap() = 1;
}
The first one runs as expected, while the second one deadlocks. Why is guard destructor being run by if but not by if let? Where can I find documentation on this behavior?