Skip to content

Use binary radix in bitflags! #11251

@Centri3

Description

@Centri3

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

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

No one assigned

    Labels

    A-lintArea: New lintsL-restrictionLint: Belongs in the restriction lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions