How come the lifeteime of Value(1) and Value(2) differs in the code below?
#![allow(irrefutable_let_patterns)]
struct Value(i32);
impl Drop for Value {
fn drop(&mut self) {
println!("Dropping Value({})", self.0);
}
}
pub fn main() {
if Value(1).0 == 1 {
println!("one!");
};
if let _ = Value(2).0 {
println!("two!");
};
}
Value(1) is dropped before the “One!”, while Value(2) is dropped after “two!”
playgroud
I would have expected both Values to be dropped before executing the println!(“one!/two!”) statements.