Closed
Description
Consider this snippet:
struct Foo<'a>(&'a mut u32);
impl<'a> Drop for Foo<'a> {
fn drop(&mut self) {
*self.0 = 0;
}
}
fn main() {
let mut foo = 0;
if let Foo(0) = Foo(&mut foo) { // Doesn't compile
} else {
*&mut foo = 1;
}
if matches!(Foo(&mut foo), Foo(0)) { // Compiles
} else {
*&mut foo = 1;
}
}
Here, if let
complains about an access of foo
in the else branch, while if
is okay with this.
This is due to if let
dropping its temporaries after the else
block. This is not neccessary, it could also drop them before.
Similar to #103107
cc @Nilstrieb
@rustbot label T-lang