Skip to content

ICE when assigning to a union with fields implementing Drop #41073

Closed
@Thinkofname

Description

@Thinkofname
#![feature(untagged_unions)]

union Test {
    a: A,
    b: B
}

#[derive(Debug)]
struct A(i32);
impl Drop for A {
    fn drop(&mut self) { println!("A"); }
}

#[derive(Debug)]
struct B(f32);
impl Drop for B {
    fn drop(&mut self) { println!("B"); }
}

fn main() {
    let mut test = Test { a: A(3) };
    println!("{:?}", unsafe { test.b });
    unsafe { test.b = B(0.5); }
}
error: internal compiler error: /checkout/src/librustc_borrowck/borrowck/mir/elaborate_drops.rs:313: drop of untracked, uninitialized value bb8, lv (_1.1: B) (Parent(Some(mp1)))
  --> <anon>:23:14
   |
23 |     unsafe { test.b = B(0.5); }
   |      

Full backtrace can be seen on the playground

https://play.rust-lang.org/?gist=bc93f5b222b09b31d3fd286cfc10858a&version=nightly&backtrace=2

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions