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

New nightly clippy warning breaks build with false positive #3020

Closed
kennykerr opened this issue May 3, 2024 · 3 comments · Fixed by #3021
Closed

New nightly clippy warning breaks build with false positive #3020

kennykerr opened this issue May 3, 2024 · 3 comments · Fixed by #3021
Labels
bug Something isn't working

Comments

@kennykerr
Copy link
Collaborator

kennykerr commented May 3, 2024

https://github.com/microsoft/windows-rs/actions/runs/8933382409/job/24538679794

Any suggestions?

This is a false positive because the kind of HSTRING the macro create is always immutable, but I guess Clippy doesn't know that. The trouble is that I can't seem to find a way to suppress the Clippy warning from within the macro_rules macro.

@kennykerr kennykerr added the bug Something isn't working label May 3, 2024
@riverar
Copy link
Collaborator

riverar commented May 3, 2024

How about something like this for now?

#[macro_export]
macro_rules! h {
    ($s:literal) => {{
        const INPUT: &[u8] = $s.as_bytes();
        const OUTPUT_LEN: usize = $crate::utf16_len(INPUT) + 1;
+       #[allow(clippy::declare_interior_mutable_const)]
        const RESULT: $crate::HSTRING = {
            if OUTPUT_LEN == 1 {
                unsafe { ::std::mem::transmute(::std::ptr::null::<u16>()) }
            } else {
                const OUTPUT: $crate::PCWSTR = $crate::w!($s);
                const HEADER: $crate::HSTRING_HEADER = $crate::HSTRING_HEADER { flags: 0x11, len: (OUTPUT_LEN - 1) as u32, padding1: 0, padding2: 0, ptr: OUTPUT.as_ptr() };
                // SAFETY: an `HSTRING` is exactly equivalent to a pointer to an `HSTRING_HEADER`
                unsafe { ::std::mem::transmute::<&$crate::HSTRING_HEADER, $crate::HSTRING>(&HEADER) }
            }
        };
+       #[allow(clippy::borrow_interior_mutable_const)]
        &RESULT
    }};
}

@kennykerr
Copy link
Collaborator Author

kennykerr commented May 3, 2024

That doesn't seem to work. It seems Clippy doesn't suppress within a macro_rules macro.

@kennykerr
Copy link
Collaborator Author

I take that back - that fix seems to work - thanks!

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