-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
A-lintArea: New lintsArea: New lintsL-restrictionLint: Belongs in the restriction lint groupLint: Belongs in the restriction lint group
Description
What it does
Checks for use of hexadecimal (0x
), decimal, octal (0o
), etc in a bitflags!
invocation, suggesting 0b
instead.
Advantage
- It's a bitflags type, so using binary is easier to understand as it doesn't require mental math to convert between the two (e.g., what bit is set for
0x1000
?).
Drawbacks
- Can be worse in cases where it matches external constants, like for example: https://learn.microsoft.com/en-us/windows/win32/Memory/memory-protection-constants, winapi documentation tends to use hexadecimal instead, so I'd expect a
Protection
bitflags to use it too. So it should berestriction
orpedantic
.
Example
bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
struct Flags: u32 {
const A = 0x1000;
}
}
Could be written as:
bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
struct Flags: u32 {
const A = 0b1000000000000;
}
}
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsL-restrictionLint: Belongs in the restriction lint groupLint: Belongs in the restriction lint group