Skip to content

Commit e838f14

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

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/codegen/impl_partialeq.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ pub fn gen_partialeq_impl(
1212
item: &Item,
1313
ty_for_impl: &proc_macro2::TokenStream,
1414
) -> Option<proc_macro2::TokenStream> {
15+
debug_assert!(
16+
!item.is_opaque(ctx, &()),
17+
"You're not supposed to call this on an opaque type"
18+
);
1519
let mut tokens = vec![];
1620

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 {
21+
if comp_info.kind() == CompKind::Union {
2222
assert!(!ctx.options().rust_features().untagged_union);
2323
tokens.push(quote! {
2424
&self.bindgen_union_field[..] == &other.bindgen_union_field[..]

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)