rust-lang / rust-lang/rust-bindgen
Make derive Debug configurable for specific structures
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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