Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't derive Copy in FFI structs/unions that contain pointers #1049

Closed
wants to merge 1 commit into from

Conversation

sdroege
Copy link
Member

@sdroege sdroege commented Feb 4, 2021

Clone is still derived to as explicitly cloning the structs is less of a
problem, but implicitly copying them can easily cause double frees.

Fixes #1048

@sdroege
Copy link
Member Author

sdroege commented Feb 4, 2021

See gtk-rs/gtk3-rs#289 for the regenerate PR.

@sdroege sdroege force-pushed the no-copy-for-pointers branch from 1ee1d81 to 2022d74 Compare February 4, 2021 14:58
@sdroege sdroege force-pushed the no-copy-for-pointers branch from 2022d74 to 2b505f0 Compare February 4, 2021 15:02
Clone is still derived to as explicitly cloning the structs is less of a
problem, but implicitly copying them can easily cause double frees.

Fixes gtk-rs#1048
@sdroege sdroege force-pushed the no-copy-for-pointers branch from 2b505f0 to 0dc1494 Compare February 4, 2021 15:05
@sdroege
Copy link
Member Author

sdroege commented Feb 4, 2021

Not complete apparently. If a struct contains a field that does not implement Copy, we still consider it Copy sometimes.

@GuillaumeGomez
Copy link
Member

Do you have an example by any chance?

@sdroege
Copy link
Member Author

sdroege commented Feb 4, 2021

error[E0204]: the trait `Copy` may not be implemented for this type
    --> glib/sys/src/lib.rs:1044:10
     |
1044 | #[derive(Copy, Clone)]
     |          ^^^^
1045 | pub union GVariantBuilder_u {
1046 |     pub s: GVariantBuilder_u_s,
     |     -------------------------- this field does not implement `Copy`
     |
     = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Another problem is also:

error[E0658]: unions with non-`Copy` fields other than `ManuallyDrop<T>` are unstable
    --> glib/sys/src/lib.rs:1046:5
     |
1046 |     pub s: GVariantBuilder_u_s,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #55149 <https://github.com/rust-lang/rust/issues/55149> for more information

@GuillaumeGomez
Copy link
Member

Oh, interesting.

@sdroege
Copy link
Member Author

sdroege commented Feb 4, 2021

I think considering that limitation for unions, we can't actually do anything meaningful here yet...

@sdroege
Copy link
Member Author

sdroege commented Feb 4, 2021

Closing as blocked on rust-lang/rust#55149

@sdroege sdroege closed this Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't derive Copy for FFI structs/unions that contain pointers
2 participants