-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
F-if_let_guard`#![feature(if_let_guard)]``#![feature(if_let_guard)]`F-let_chains`#![feature(let_chains)]``#![feature(let_chains)]`T-langRelevant to the language teamRelevant to the language team
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
IndigoLily and r58Playz
Metadata
Metadata
Assignees
Labels
F-if_let_guard`#![feature(if_let_guard)]``#![feature(if_let_guard)]`F-let_chains`#![feature(let_chains)]``#![feature(let_chains)]`T-langRelevant to the language teamRelevant to the language team