Skip to content

#[derive] is used on #[repr(packed)] struct that does not derive Copy (E0133) #2083

@rhdxmr

Description

@rhdxmr

Thank you @emilio for fixing the last issue.

I have another issue here.
I am using rust 1.53 and bindgen 0.59.1

Input C/C++ Header

struct packed_wo_copy {
        short f1;
        char f2[0];
} __attribute__((packed));

Actual Results

#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
impl<T> __IncompleteArrayField<T> {
    #[inline]
    pub const fn new() -> Self {
        __IncompleteArrayField(::std::marker::PhantomData, [])
    }
    #[inline]
    pub fn as_ptr(&self) -> *const T {
        self as *const _ as *const T
    }
    #[inline]
    pub fn as_mut_ptr(&mut self) -> *mut T {
        self as *mut _ as *mut T
    }
    #[inline]
    pub unsafe fn as_slice(&self, len: usize) -> &[T] {
        ::std::slice::from_raw_parts(self.as_ptr(), len)
    }
    #[inline]
    pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
        ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
    }
}
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
    fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
        fmt.write_str("__IncompleteArrayField")
    }
}
#[repr(C, packed)]
#[derive(Debug)]
pub struct packed_wo_copy {
    pub f1: ::std::os::raw::c_short,
    pub f2: __IncompleteArrayField<::std::os::raw::c_char>,
}

and compilation errors generated when compiling the bindings with rustc

warning: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
  --> packed.rs:34:10
   |
34 | #[derive(Debug)]
   |          ^^^^^
   |
   = note: `#[warn(unaligned_references)]` 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
   = note: this warning originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted

Expected Results

Maybe no Debug derivative?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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