Skip to content

Make derive Debug configurable for specific structures #1491

@andreeaflorescu

Description

@andreeaflorescu

Input C/C++ Header

# Taken from include/uapi/linux/virtio_net.h
struct virtio_net_ctrl_mac {
    __virtio32 entries;
    __u8 macs[][ETH_ALEN];
} __attribute__((packed));

Bindgen Invocation

# Bindgen version: 0.46.0
$  bindgen include/linux/virtio_net.h -o virtio_net.rs --with-derive-default --with-derive-partialeq

Actual Results

#[repr(C, packed)]
#[derive(Debug, Default)]
pub struct virtio_net_ctrl_mac {
    pub entries: __virtio32,
    pub macs: __IncompleteArrayField<[__u8; 6usize]>,
}

Compilation Warning:

warning: #[derive] can't be used on a #[repr(packed)] struct that does not derive Copy (error E0133)                                                                                                                                                                               
   --> virtio_gen/src/virtio_net.rs:684:10                                                                                                                                                                                                                                         
    |                                                                                                                                                                                                                                                                              
684 | #[derive(Debug, Default)]                                                                                                                                                                                                                                                    
    |          ^^^^^                                                                                                                                                                                                                                                               
    |                                                                                                                                                                                                                                                                              
    = note: #[warn(safe_packed_borrows)] on by default                                                                                                                                                                                                                             
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!                                                                                                                                              
    = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>        

Nice to have behaviour

We would like to be able to specify structures for which we want derive debug to be excluded (for example virtio_net_ctrl_mac) so we can automatically generate bindings. Our workaround right now is to manually remove the debug derive.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions