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

Bug: Custom metadata referencing windows::Win32::Foundation::BOOL fails to build with missing Debug trait #1390

Closed
wravery opened this issue Dec 18, 2021 · 3 comments · Fixed by #1395
Labels
bug Something isn't working

Comments

@wravery
Copy link
Collaborator

wravery commented Dec 18, 2021

Which crate is this about?

windows

Crate version

0.29.0

Summary

This is the generated windows.rs file from when I tried to migrate https://github.com/wravery/webview2-rs/tree/next to 0.29.0:

                impl ::core::fmt::Debug for COREWEBVIEW2_PHYSICAL_KEY_STATUS {
                    fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                        fmt.debug_struct("COREWEBVIEW2_PHYSICAL_KEY_STATUS")
                            .field("RepeatCount", &self.RepeatCount)
                            .field("ScanCode", &self.ScanCode)
                            .field("IsExtendedKey", &self.IsExtendedKey)
                            .field("IsMenuKeyDown", &self.IsMenuKeyDown)
                            .field("WasKeyDown", &self.WasKeyDown)
                            .field("IsKeyReleased", &self.IsKeyReleased)
                            .finish()
                    }
                }

Expected behavior

It should build just fine. It doesn't, because it complains that windows::Win32::Foundation::BOOL is missing an implementation of Debug, so it can't compile this function for IsExtendedKey or the other BOOL members in this struct.

Actual behavior

error[E0277]: `BOOL` doesn't implement `Debug`
   --> C:\repos\wravery\webview2-rs\target\debug\build\webview2-com-sys-bb3de26d494647cb\out/windows.rs:577:53
    |
577 | ...                   .field("IsExtendedKey", &self.IsExtendedKey)
    |                                               ^^^^^^^^^^^^^^^^^^^ `BOOL` cannot be formatted using `{:?}` because it doesn't implement `Debug`
    |
    = help: the trait `Debug` is not implemented for `BOOL`
    = note: required for the cast to the object type `dyn Debug`

error[E0277]: `BOOL` doesn't implement `Debug`
   --> C:\repos\wravery\webview2-rs\target\debug\build\webview2-com-sys-bb3de26d494647cb\out/windows.rs:578:53
    |
578 | ...                   .field("IsMenuKeyDown", &self.IsMenuKeyDown)
    |                                               ^^^^^^^^^^^^^^^^^^^ `BOOL` cannot be formatted using `{:?}` because it doesn't implement `Debug`
    |
    = help: the trait `Debug` is not implemented for `BOOL`
    = note: required for the cast to the object type `dyn Debug`

error[E0277]: `BOOL` doesn't implement `Debug`
   --> C:\repos\wravery\webview2-rs\target\debug\build\webview2-com-sys-bb3de26d494647cb\out/windows.rs:579:50
    |
579 | ...                   .field("WasKeyDown", &self.WasKeyDown)
    |                                            ^^^^^^^^^^^^^^^^ `BOOL` cannot be formatted using `{:?}` because it doesn't implement `Debug`
    |
    = help: the trait `Debug` is not implemented for `BOOL`
    = note: required for the cast to the object type `dyn Debug`

error[E0277]: `BOOL` doesn't implement `Debug`
   --> C:\repos\wravery\webview2-rs\target\debug\build\webview2-com-sys-bb3de26d494647cb\out/windows.rs:580:53
    |
580 | ...                   .field("IsKeyReleased", &self.IsKeyReleased)
    |                                               ^^^^^^^^^^^^^^^^^^^ `BOOL` cannot be formatted using `{:?}` because it doesn't implement `Debug`
    |
    = help: the trait `Debug` is not implemented for `BOOL`
    = note: required for the cast to the object type `dyn Debug`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `webview2-com-sys` due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
error: build failed

Additional comments

This repros with the latest stable toolchain:

> rustc --version
rustc 1.57.0 (f1edd0429 2021-11-29)
@wravery wravery added the bug Something isn't working label Dec 18, 2021
@kennykerr
Copy link
Collaborator

Ah, the build/generate macros are still based on the old gen crate while everything else has moved over to the new bindgen crate. That's what's causing the discrepancy. I'll add a test for this and push out a fix as soon as I get a moment.

By the way, the build/generate macros will also soon be removed.

@wravery
Copy link
Collaborator Author

wravery commented Dec 20, 2021

By the way, the build/generate macros will also soon be removed.

Should I replace that with something else?

@kennykerr
Copy link
Collaborator

Yes, the underlying code gen library used by the windows/windows-sys crates is now available here:

https://crates.io/crates/windows-bindgen
https://docs.rs/windows-bindgen

As you can see, it is really simple. Here's how you might use it to generate individual types:

https://github.com/microsoft/windows-rs/blob/master/crates/tools/bindings/src/main.rs

Or entire namespaces:

https://github.com/microsoft/windows-rs/blob/master/crates/tools/api/src/main.rs

Still testing and working out wrinkles, which is why the old build/generate macros are still around temporarily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants