Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rhdxmr opened this issue Jul 26, 2021 · 4 comments · Fixed by #2200
Closed

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

rhdxmr opened this issue Jul 26, 2021 · 4 comments · Fixed by #2200

Comments

@rhdxmr
Copy link

rhdxmr commented Jul 26, 2021

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?

@emilio
Copy link
Contributor

emilio commented Jul 26, 2021

Is this a regression from 0.59 as well?

@rhdxmr
Copy link
Author

rhdxmr commented Jul 26, 2021

@emilio
It seems not a regression.
I just tested the input with bindgen 0.40, 0.50, 0.58, but the same compilation warning raises.

@vadorovsky
Copy link
Contributor

Hitting this error as well (when generating bindings to kernel structs for eBPF), with the newest bindgen and rust nightly.

@vadorovsky
Copy link
Contributor

Actually now it's an error, not a warning:

error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
     --> src/vmlinux.rs:11701:10
      |
11701 | #[derive(Debug)]
      |          ^^^^^
      |
      = note: `#[deny(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 error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

vadorovsky added a commit to vadorovsky/aya that referenced this issue May 4, 2022
It's a workaround for the upstream bindgen issue:

rust-lang/rust-bindgen#2083

tl;dr: Rust nightly complains about #[repr(packed)] structs deriving
Debug without Copy.

It needs to be fixed properly upstream, but for now we have to disable
Debug derive here.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trair when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trair when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 4, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 5, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
vadorovsky added a commit to vadorovsky/rust-bindgen that referenced this issue May 5, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
emilio pushed a commit that referenced this issue May 7, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: #2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
fasterthanlime pushed a commit to fasterthanlime/aya that referenced this issue May 20, 2022
It's a workaround for the upstream bindgen issue:

rust-lang/rust-bindgen#2083

tl;dr: Rust nightly complains about #[repr(packed)] structs deriving
Debug without Copy.

It needs to be fixed properly upstream, but for now we have to disable
Debug derive here.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
aatifsyed pushed a commit to aatifsyed/rust-bindgen that referenced this issue Sep 22, 2022
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
dmitris added a commit to dmitris/aya that referenced this issue Feb 9, 2023
The comment says that `.derive_debug` was needed as
a workaround for rust-lang/rust-bindgen#2083.
This issue is now closed, and aya-tool compiles without derive_debug.

Additionally, update bindgen dependency to 1.64.0.

Signed-off-by: Dmitry Savintsev <dsavints@gmail.com>
dmitris added a commit to dmitris/aya that referenced this issue Feb 9, 2023
The comment says that `.derive_debug` was needed as
a workaround for rust-lang/rust-bindgen#2083.
This issue is now closed, and aya-tool compiles without derive_debug.

Additionally, update bindgen dependency to 1.64.

Signed-off-by: Dmitry Savintsev <dsavints@gmail.com>
scottlamb added a commit to sportsball-ai/av-rs that referenced this issue Jun 21, 2023
One version is easier to keep track of and should reduce build times.

* replace ffmpeg-sys with ffmpeg-sys-next, which (among other things)
  uses bindgen 0.64. ffmpeg-sys was using a pre-0.60 version, so in
  some of our call sites, it hit build errors on Rust 1.70 due to
  rust-lang/rust-bindgen#2083
  https://github.com/rust-lang/rust-bindgen/blob/main/CHANGELOG.md#0600

* update cargo lock stuff to use the same version

* remove stale comments about older versions
scottlamb added a commit to sportsball-ai/av-rs that referenced this issue Jun 22, 2023
* use ffmpeg-sys-next, single version of bindgen

One version is easier to keep track of and should reduce build times.

* replace ffmpeg-sys with ffmpeg-sys-next, which (among other things)
  uses bindgen 0.64. ffmpeg-sys was using a pre-0.60 version, so in
  some of our call sites, it hit build errors on Rust 1.70 due to
  rust-lang/rust-bindgen#2083
  https://github.com/rust-lang/rust-bindgen/blob/main/CHANGELOG.md#0600

* update cargo lock stuff to use the same version

* remove stale comments about older versions

* fix xilinx build errors with bindgen 0.64
LoganBarnett pushed a commit to LoganBarnett/rust-bindgen that referenced this issue Dec 2, 2023
It's impossible to #[derive] from any other trait when not deriving from
Copy when using the newest Rust nightly. Any attempt to do that results
in the following error:

  error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)

Fixes: rust-lang#2083
Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants