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

clippy::manual_bits should not be detected in macros #13563

Open
orlp opened this issue Oct 18, 2024 · 1 comment · May be fixed by #13564
Open

clippy::manual_bits should not be detected in macros #13563

orlp opened this issue Oct 18, 2024 · 1 comment · May be fixed by #13564
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@orlp
Copy link

orlp commented Oct 18, 2024

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

@orlp orlp added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 18, 2024
@GnomedDev
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants