Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bindgen-tests/tests/headers/typedef-void-newtype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// bindgen-flags: --new-type-alias myvoid --with-derive-hash --with-derive-partialeq --with-derive-partialord --with-derive-eq --with-derive-ord --impl-debug --impl-partialeq
typedef void myvoid;
10 changes: 8 additions & 2 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,11 @@ impl CodeGenerator for Type {
needs_debug_impl = ctx.options().derive_debug &&
ctx.options().impl_debug &&
!ctx.no_debug_by_name(item) &&
!item.annotations().disallow_debug();
!item.annotations().disallow_debug() &&
!item.as_type().is_some_and(|ty| {
ty.safe_canonical_type(ctx)
.is_some_and(|ty| ty.is_void())
});
}
let mut derives: Vec<_> = derivable_traits.into();
// The custom derives callback may return a list of derive attributes;
Expand All @@ -1126,7 +1130,9 @@ impl CodeGenerator for Type {
});
// In most cases this will be a no-op, since custom_derives will be empty.
append_custom_derives(&mut derives, &custom_derives);
attributes.push(attributes::derives(&derives));
if !derives.is_empty() {
attributes.push(attributes::derives(&derives));
}

let custom_attributes =
ctx.options().all_callbacks(|cb| {
Expand Down
3 changes: 1 addition & 2 deletions bindgen/ir/analysis/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ impl CannotDerive<'_> {
match *ty.kind() {
// Handle the simple cases. These can derive traits without further
// information.
TypeKind::Void |
TypeKind::NullPtr |
TypeKind::Int(..) |
TypeKind::Complex(..) |
Expand All @@ -213,6 +212,7 @@ impl CannotDerive<'_> {
TypeKind::Function(ref sig) => {
self.derive_trait.can_derive_fnptr(sig)
}
TypeKind::Void => CanDerive::No,

// Complex cases need more information
TypeKind::Array(t, len) => {
Expand Down Expand Up @@ -534,7 +534,6 @@ impl DeriveTrait {
// === Default ===
(
DeriveTrait::Default,
TypeKind::Void |
TypeKind::NullPtr |
TypeKind::Enum(..) |
TypeKind::Reference(..) |
Expand Down
Loading