Open marcbowes opened 2 years ago
The error is correct. An explicit return causes the drop order of temporaries to change. For example, see the following code:
struct Loud(i32);
impl Drop for Loud {
fn drop(&mut self) {
println!("dropped {}", self.0);
}
}
fn dummy(_: &Loud) -> i32 { 1 }
fn foo() -> i32 {
let _x = Loud(1);
dummy(&Loud(2))
}
fn bar() -> i32 {
let _x = Loud(3);
return dummy(&Loud(4));
}
fn main() {
foo();
bar();
}
Output:
dropped 1
dropped 2
dropped 4
dropped 3
See also #69367
I tried this code:
I expected to see this happen: it compiles!
Instead, this happened:
What's weird is changing to an explicit return fixes the problem:
Meta
rustc --version --verbose
: