Skip to content

Debug trait is derived when a struct contains __bindgen_padding #648

Closed
@leeopop

Description

@leeopop

Input C/C++ Header

/** The data structure associated with each crypto device. */
struct rte_cryptodev {
        dequeue_pkt_burst_t dequeue_burst;
        /**< Pointer to PMD receive function. */
        enqueue_pkt_burst_t enqueue_burst;
        /**< Pointer to PMD transmit function. */

        const struct rte_cryptodev_driver *driver;
        /**< Driver for this device */
        struct rte_cryptodev_data *data;
        /**< Pointer to device data */
        struct rte_cryptodev_ops *dev_ops;
        /**< Functions exported by PMD */
        uint64_t feature_flags;
        /**< Supported features */
        struct rte_device *device;
        /**< Backing device */

        enum rte_cryptodev_type dev_type;
        /**< Crypto device type */

        struct rte_cryptodev_cb_list link_intr_cbs;
        /**< User application callback for interrupts if present */

        __extension__
        uint8_t attached : 1;
        /**< Flag indicating the device is attached */
} __rte_cache_aligned;

__rte_cache_aligned is 64byte alignment.

Bindgen Invokation

    bindgen::builder()
        .header(header_path.to_str().unwrap())
        .no_unstable_rust()
        .clang_arg(format!("-I{}", dpdk_include_path.to_str().unwrap()))
        .clang_arg(format!("-I{}", c_include_path.to_str().unwrap()))
        .clang_arg("-imacros")
        .clang_arg(dpdk_config_path.to_str().unwrap())
        .clang_arg("-march=native")
        .generate()
        .unwrap()
        .write_to_file(target_path)
        .ok();

Actual Results

#[repr(C)]
#[derive(Debug, Copy)]
pub struct rte_cryptodev {
    pub dequeue_burst: dequeue_pkt_burst_t,
    pub enqueue_burst: enqueue_pkt_burst_t,
    pub driver: *const rte_cryptodev_driver,
    pub data: *mut rte_cryptodev_data,
    pub dev_ops: *mut rte_cryptodev_ops,
    pub feature_flags: u64,
    pub device: *mut rte_device,
    pub dev_type: rte_cryptodev_type,
    pub link_intr_cbs: rte_cryptodev_cb_list,
    pub _bitfield_1: u8,
    pub __bindgen_padding_0: [u8; 47usize],
}
   Compiling bindgen v0.23.1 (https://github.com/servo/rust-bindgen.git?rev=f775f1f#f775f1f2)
   Compiling rust-dpdk v0.0.1-dev (file:///home/leeopop/git/rust-dpdk)
error[E0277]: the trait bound `[u8; 47]: std::fmt::Debug` is not satisfied
     --> /home/leeopop/git/rust-dpdk/src/dpdk.rs:18040:5
      |
18040 |     pub __bindgen_padding_0: [u8; 47usize],
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::fmt::Debug` is not implemented for `[u8; 47]`
      |
      = note: `[u8; 47]` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
      = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 47]`
      = note: required for the cast to the object type `std::fmt::Debug`

Expected Results

This structure contains [u8; 47] which does not implement Debug trait.
By the way, does [u8; 47] implements Copy trait?
struct rte_cryptodev should not derive Debug and Copy trait also.

#458

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions