rust-lang / rust-lang/rust-bindgen

Make derive Debug configurable for specific structures

Open
#1,491 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how bindgen handles --with-derive-default and emits derives for the shown packed struct; the issue names no source file or test. Done means providing a configurable exclusion for Debug on selected structures, with coverage for virtio_net_ctrl_mac while preserving the other requested derives.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.