1 // This is a reduction of a concrete test illustrating a case that was
2 // annoying to Rust developer niconii (see comment thread on #21114).
4 // With resolving issue #54556, pnkfelix hopes that the new diagnostic
5 // output produced by NLL helps to *explain* the semantic significance
6 // of temp drop order, and thus why inserting a semi-colon after the
7 // `if let` expression in `main` works.
10 struct MutexGuard<'a>(&'a Mutex);
12 impl Drop for Mutex { fn drop(&mut self) { println!("Mutex::drop"); } }
13 impl<'a> Drop for MutexGuard<'a> { fn drop(&mut self) { println!("MutexGuard::drop"); } }
16 fn lock(&self) -> Result<MutexGuard, ()> { Ok(MutexGuard(self)) }
22 if let Ok(_) = counter.lock() { } //~ ERROR does not live long enough
24 // With this code as written, the dynamic semantics here implies
25 // that `Mutex::drop` for `counter` runs *before*
26 // `MutexGuard::drop`, which would be unsound since `MutexGuard`
27 // still has a reference to `counter`.
29 // The goal of #54556 is to explain that within a compiler