You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Partially moved" unions are dropped incorrectly #36246
#![feature(untagged_unions)]
#![allow(unused)]
struct S;
struct Z;
impl Drop for S { fn drop(&mut self) { println!("S"); } }
impl Drop for Z { fn drop(&mut self) { println!("Z"); } }
#[allow(unions_with_drop_fields)]
union U {
s: S,
z: Z,
}
fn main() {
let u = U { s: S };
let s = unsafe { u.s }; // Move `u.s` out of `u`.
// Drop `s`.
// Drop `u`, noop.
}
Expected output:
S
Actual output:
S
Z
i.e. u.z is dropped too for some reason.
This is probably caused by some union-specific logic missing from librustc_borrowck/borrowck/fragments.rs and librustc_borrowck/borrowck/mir/.
Activity
pnkfelix commentedon Sep 5, 2016
cc #32836 (should ensure this is fixed before feature is stabilized)
joshtriplett commentedon Sep 6, 2016
Interestingly, if you remove the Drop impl for
S, then Z's drop doesn't get called either.