Skip to content

Commit

Permalink
Derive from any other trait only when deriving from Copy
Browse files Browse the repository at this point in the history
It's impossible to #[derive] from any other trair when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
  • Loading branch information
vadorovsky committed May 4, 2022
1 parent ee6ff69 commit c994f5a
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ bitflags! {
fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits {
let mut derivable_traits = DerivableTraits::empty();

if item.can_derive_debug(ctx) && !item.annotations().disallow_debug() {
derivable_traits |= DerivableTraits::DEBUG;
}

if item.can_derive_default(ctx) && !item.annotations().disallow_default() {
derivable_traits |= DerivableTraits::DEFAULT;
}

let all_template_params = item.all_template_params(ctx);

if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() {
Expand All @@ -137,26 +129,34 @@ fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits {
// It's not hard to fix though.
derivable_traits |= DerivableTraits::CLONE;
}
}

if item.can_derive_hash(ctx) {
derivable_traits |= DerivableTraits::HASH;
}
if item.can_derive_debug(ctx) && !item.annotations().disallow_debug() {
derivable_traits |= DerivableTraits::DEBUG;
}

if item.can_derive_partialord(ctx) {
derivable_traits |= DerivableTraits::PARTIAL_ORD;
}
if item.can_derive_default(ctx) && !item.annotations().disallow_default() {
derivable_traits |= DerivableTraits::DEFAULT;
}

if item.can_derive_ord(ctx) {
derivable_traits |= DerivableTraits::ORD;
}
if item.can_derive_hash(ctx) {
derivable_traits |= DerivableTraits::HASH;
}

if item.can_derive_partialeq(ctx) {
derivable_traits |= DerivableTraits::PARTIAL_EQ;
}
if item.can_derive_partialord(ctx) {
derivable_traits |= DerivableTraits::PARTIAL_ORD;
}

if item.can_derive_eq(ctx) {
derivable_traits |= DerivableTraits::EQ;
if item.can_derive_ord(ctx) {
derivable_traits |= DerivableTraits::ORD;
}

if item.can_derive_partialeq(ctx) {
derivable_traits |= DerivableTraits::PARTIAL_EQ;
}

if item.can_derive_eq(ctx) {
derivable_traits |= DerivableTraits::EQ;
}
}

derivable_traits
Expand Down

0 comments on commit c994f5a

Please sign in to comment.