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

Heads-up: winapi 0.2.8 will fail to build soon-ish #1030

Closed
RalfJung opened this issue Oct 24, 2022 · 4 comments
Closed

Heads-up: winapi 0.2.8 will fail to build soon-ish #1030

RalfJung opened this issue Oct 24, 2022 · 4 comments

Comments

@RalfJung
Copy link

In rust-lang/rust#102513 we are moving ahead with finally closing the ancient soundness issue rust-lang/rust#82523 (originally tracked at rust-lang/rust#27060): we are disallowing creating references to fields of packed structs. It seems like that will make winapi 0.2.8 fail to build:

error[E0791]: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
    |
    |
263 |           #[repr(C)] #[derive(Debug)] $(#[$attrs])*
    |
   ::: C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.2.8\src\mmreg.rs:290:1
    |
    |
290 | / STRUCT!{#[repr(packed)] struct WAVEFORMATEX {
291 | |     wFormatTag: ::WORD,
292 | |     nChannels: ::WORD,
293 | |     nSamplesPerSec: ::DWORD,
297 | |     cbSize: ::WORD,
298 | | }}
    | |__- in this macro invocation
    |
    |
    = note: this error originates in the derive macro `Debug` which comes from the expansion of the macro `STRUCT` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0791]: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
    |
    |
263 |           #[repr(C)] #[derive(Debug)] $(#[$attrs])*
    |
   ::: C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.2.8\src\mmreg.rs:299:1
    |
    |
299 | / STRUCT!{#[repr(packed)] struct WAVEFORMATEXTENSIBLE {
300 | |     Format: ::WAVEFORMATEX,
301 | |     Samples: ::WORD,
302 | |     dwChannelMask: ::DWORD,
303 | |     SubFormat: ::GUID,
304 | | }}
    |
    = note: this error originates in the derive macro `Debug` which comes from the expansion of the macro `STRUCT` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0791]: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
    |
    |
263 |           #[repr(C)] #[derive(Debug)] $(#[$attrs])*
    |
    |
   ::: C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.2.8\src\usbspec.rs:26:1
    |
26  | / STRUCT!{#[repr(packed)] struct USB_CONFIGURATION_DESCRIPTOR {
27  | |     bLength: ::UCHAR,
28  | |     bDescriptorType: ::UCHAR,
29  | |     wTotalLength: ::USHORT,
...   |
34  | |     MaxPower: ::UCHAR,
35  | | }}
    |
    = note: this error originates in the derive macro `Debug` which comes from the expansion of the macro `STRUCT` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0791]: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
    |
    |
263 |           #[repr(C)] #[derive(Debug)] $(#[$attrs])*
    |
   ::: C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\winapi-0.2.8\src\winusb.rs:8:1
    |
    |
8   | / STRUCT!{#[repr(packed)] struct WINUSB_SETUP_PACKET {
9   | |     RequestType: ::UCHAR,
10  | |     Request: ::UCHAR,
11  | |     Value: ::USHORT,
12  | |     Index: ::USHORT,
13  | |     Length: ::USHORT,
14  | | }}
    |
    = note: this error originates in the derive macro `Debug` which comes from the expansion of the macro `STRUCT` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0791`.

It looks like current versions of winapi avoid that error by deriving Copy for those structs.

I am not sure if there is anything you want to do about this -- winapi 0.2.8 seems to not be supported any more. However, given how widely used this crate is, it still might make sense to do a patch release so that people can fix their build with cargo update. If you want to do that, I'm open to waiting a bit before landing the rustc PR so that you can get the patch release out first.

@RalfJung
Copy link
Author

I wrote a patch that fixes the build and pushed it to https://github.com/RalfJung/winapi-rs/tree/0.2. I am not entirely sure, however, if there was some reason why Copy was implemented instead of derived?

@tbu-
Copy link

tbu- commented Dec 25, 2022

It might have been implemented instead of derived due to compile-duration concerns.

Is there a reason why the derived Debug implementation cannot take the implemented Copy into account? This would solve the issue in a backward compatible way.

@RalfJung
Copy link
Author

RalfJung commented Dec 26, 2022 via email

@RalfJung
Copy link
Author

We ended up changing the implementation of derive on packed types to keep winapi 0.2 working, see rust-lang/rust#104429.

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

No branches or pull requests

2 participants