immunant / c2rust

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

analyze: remove #[derive(Copy, Clone)] when rewrites make the struct non-cloneable #951

Open spernsteiner opened 1 year ago

spernsteiner commented 1 year ago

c2rust-transpile seems to generate #[derive(Copy, Clone)] on all structs. When rewriting a struct in a way that makes it non-cloneable, such as changing a *mut i32 field to &mut i32, we should remove those derives, since they are no longer valid.

kkysen commented 1 year ago

I encountered this on rav1d, too. The one caveat is that unions require Copy fields, so unless we can turn them into enums, we can't rewrite fields into non-Copy types like references.