Skip to content

Commit c994f5a

Browse files
committed
Derive from any other trait only when deriving from Copy
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 <[email protected]>
1 parent ee6ff69 commit c994f5a

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/codegen/mod.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ bitflags! {
113113
fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits {
114114
let mut derivable_traits = DerivableTraits::empty();
115115

116-
if item.can_derive_debug(ctx) && !item.annotations().disallow_debug() {
117-
derivable_traits |= DerivableTraits::DEBUG;
118-
}
119-
120-
if item.can_derive_default(ctx) && !item.annotations().disallow_default() {
121-
derivable_traits |= DerivableTraits::DEFAULT;
122-
}
123-
124116
let all_template_params = item.all_template_params(ctx);
125117

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

142-
if item.can_derive_hash(ctx) {
143-
derivable_traits |= DerivableTraits::HASH;
144-
}
133+
if item.can_derive_debug(ctx) && !item.annotations().disallow_debug() {
134+
derivable_traits |= DerivableTraits::DEBUG;
135+
}
145136

146-
if item.can_derive_partialord(ctx) {
147-
derivable_traits |= DerivableTraits::PARTIAL_ORD;
148-
}
137+
if item.can_derive_default(ctx) && !item.annotations().disallow_default() {
138+
derivable_traits |= DerivableTraits::DEFAULT;
139+
}
149140

150-
if item.can_derive_ord(ctx) {
151-
derivable_traits |= DerivableTraits::ORD;
152-
}
141+
if item.can_derive_hash(ctx) {
142+
derivable_traits |= DerivableTraits::HASH;
143+
}
153144

154-
if item.can_derive_partialeq(ctx) {
155-
derivable_traits |= DerivableTraits::PARTIAL_EQ;
156-
}
145+
if item.can_derive_partialord(ctx) {
146+
derivable_traits |= DerivableTraits::PARTIAL_ORD;
147+
}
157148

158-
if item.can_derive_eq(ctx) {
159-
derivable_traits |= DerivableTraits::EQ;
149+
if item.can_derive_ord(ctx) {
150+
derivable_traits |= DerivableTraits::ORD;
151+
}
152+
153+
if item.can_derive_partialeq(ctx) {
154+
derivable_traits |= DerivableTraits::PARTIAL_EQ;
155+
}
156+
157+
if item.can_derive_eq(ctx) {
158+
derivable_traits |= DerivableTraits::EQ;
159+
}
160160
}
161161

162162
derivable_traits

0 commit comments

Comments
 (0)