Skip to content

Commit 557732e

Browse files
committed
Disallow Copy/Clone/Eq*/Ord* for opaque types
1 parent ec85170 commit 557732e

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/codegen/impl_partialeq.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ pub fn gen_partialeq_impl(
1414
) -> Option<proc_macro2::TokenStream> {
1515
let mut tokens = vec![];
1616

17-
if item.is_opaque(ctx, &()) {
18-
tokens.push(quote! {
19-
&self._bindgen_opaque_blob[..] == &other._bindgen_opaque_blob[..]
20-
});
21-
} else if comp_info.kind() == CompKind::Union {
17+
if comp_info.kind() == CompKind::Union {
2218
assert!(!ctx.options().rust_features().untagged_union);
2319
tokens.push(quote! {
2420
&self.bindgen_union_field[..] == &other.bindgen_union_field[..]
2521
});
26-
} else {
22+
} else if !item.is_opaque(ctx, &()) {
2723
for base in comp_info.base_members().iter() {
2824
if !base.requires_storage(ctx) {
2925
continue;

src/ir/item.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -325,37 +325,37 @@ impl CanDeriveDefault for Item {
325325

326326
impl CanDeriveCopy for Item {
327327
fn can_derive_copy(&self, ctx: &BindgenContext) -> bool {
328-
self.id().can_derive_copy(ctx)
328+
self.id().can_derive_copy(ctx) && !self.is_opaque(ctx, &())
329329
}
330330
}
331331

332332
impl CanDeriveHash for Item {
333333
fn can_derive_hash(&self, ctx: &BindgenContext) -> bool {
334-
self.id().can_derive_hash(ctx)
334+
self.id().can_derive_hash(ctx) && !self.is_opaque(ctx, &())
335335
}
336336
}
337337

338338
impl CanDerivePartialOrd for Item {
339339
fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool {
340-
self.id().can_derive_partialord(ctx)
340+
self.id().can_derive_partialord(ctx) && !self.is_opaque(ctx, &())
341341
}
342342
}
343343

344344
impl CanDerivePartialEq for Item {
345345
fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool {
346-
self.id().can_derive_partialeq(ctx)
346+
self.id().can_derive_partialeq(ctx) && !self.is_opaque(ctx, &())
347347
}
348348
}
349349

350350
impl CanDeriveEq for Item {
351351
fn can_derive_eq(&self, ctx: &BindgenContext) -> bool {
352-
self.id().can_derive_eq(ctx)
352+
self.id().can_derive_eq(ctx) && !self.is_opaque(ctx, &())
353353
}
354354
}
355355

356356
impl CanDeriveOrd for Item {
357357
fn can_derive_ord(&self, ctx: &BindgenContext) -> bool {
358-
self.id().can_derive_ord(ctx)
358+
self.id().can_derive_ord(ctx) && !self.is_opaque(ctx, &())
359359
}
360360
}
361361

0 commit comments

Comments
 (0)