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

Prevent default derives for Forward declared types. #3110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jschwe
Copy link
Contributor

@jschwe jschwe commented Feb 2, 2025

We do not know the layout for forward declared types.
Deriving Copy, Clone, Hash, PartialEq etc. is simply wrong.
Deriving Debug is debatable, since it can't print anything
useful. Since we previously would derive Debug, lets just
keep it, to avoid needless breaking changes.

Changed tests:

  • func-return-must-use: Don't use forward declared structs in the
      test, since that would result in wrong bindings!
  • issue-1238-fwd-no-copy test no longer requires an annotation,
      since Forward declared types should always be no copy
  • forward-declaration-autoptr.rs: Manually implement clone.
      The inner type is unknown, so requiring clone/copy is not correct.

Fixes #1656

@jschwe jschwe force-pushed the jschwender/derives_on_fwd_decls branch from c196db6 to 930a6ac Compare February 3, 2025 13:01
We do not know the layout for forward declared types.
Deriving Copy, Clone, Hash, PartialEq etc. is simply wrong.
Deriving Debug is debatable, since it can't print anything
useful. Since we previously would derive Debug, lets just
keep it, to avoid needless breaking changes.

Changed tests:
- func-return-must-use: Don't use forward declared structs in the
  test, since that would result in wrong bindings!
- issue-1238-fwd-no-copy test no longer requires an annotation,
  since Forward declared types should always be no copy
- forward-declaration-autoptr.rs: Manually implement clone.
  The inner type is unknown, so requiring clone/copy is not correct.
@jschwe jschwe force-pushed the jschwender/derives_on_fwd_decls branch from 930a6ac to 102152c Compare February 3, 2025 13:29
@@ -20,7 +20,7 @@ impl<T> Default for RefPtr<T> {
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[derive(Debug)]
Copy link
Contributor Author

@jschwe jschwe Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think losing Copy, Clone here (on the RefPtr) may be undesired. It seems that bindgen would also need to manually implement the trait instead of deriving it, since Foo is neither Copy nor Clone

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.

Do not derive Clone/Copy/etc for opaque types
1 participant