Closed
Description
Summary
Using size_of::<$T>() * 8
is a fully generic way in macros to get the size of some type $T
in bits. This allows the macro to be used for any kind of type. If this macro is then used on a numeric type clippy should not tell you to use BITS
because it's possible, perhaps even likely, that the macro is also used for non-numeric types.
Lint Name
clippy::manual_bits
Reproducer
macro_rules! some_macro {
($T: ty) => {
let bits = size_of::<$T>() * 8;
dbg!(bits);
}
}
fn main() {
some_macro!(u32);
some_macro!(String);
}
Version
rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: aarch64-apple-darwin
release: 1.80.1
LLVM version: 18.1.7
Additional Labels
No response