Closed
Description
I was playing around with #21407, and I think I found a distinct bug in FRU – if a field initialiser escapes (panics/returns/break
s), some of the fields in the original struct get leaked.
For example:
struct Noisy(u32);
impl Drop for Noisy {
fn drop(&mut self) {
println!("splat #{}!", self.0);
}
}
struct Foo { n0: Noisy, n1: Noisy }
fn leak() -> Foo {
let old_foo = Foo { n0: Noisy(0), n1: Noisy(1) };
Foo { n0: { return Foo { n0: Noisy(3), n1: Noisy(4) } }, ..old_foo } ;
}
fn main() {
drop(leak());
}
This prints
splat #0!
splat #3!
splat #4!
Observe that the Noisy(1)
is never destroyed.