immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.95k stars 234 forks source link

analyze: bad rewrite of `derive(Clone)` on unions #990

Closed spernsteiner closed 1 year ago

spernsteiner commented 1 year ago
#[derive(Copy, Clone)]
pub union Foo {
    x: usize,
    y: *mut u8,
}

This gets rewritten to

#[derive(Copy, &Foo)]
pub union Foo {
    x: usize,
    y: *mut u8,
}

Note the derive(Copy, &Foo), which is invalid. This seems related to pointers and/or hypothetical lifetimes, since the issue doesn't occur when all fields of the union are integers like i32.

This looks similar to #952, but might have a different cause, since essentially every part of the derive(Clone) output gets assigned the span of the token Clone.