Closed kennykerr closed 3 months ago
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
}};
}
That doesn't seem to work. It seems Clippy doesn't suppress within a macro_rules
macro.
I take that back - that fix seems to work - thanks!
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 themacro_rules
macro.