Skip to content

Lint masking bits and shift #6632

Open
Open

Description

What it does

Consider this code snippet:

pub const fn to_4_be_nibles(op: u16) -> [u8; 4] {
    [
        (op & 0xF000 >> 12) as u8,
        (op & 0x0F00 >> 8) as u8,
        (op & 0x00F0 >> 4) as u8,
        (op & 0x000F) as u8,
    ]
}

We'd realize that the code is wrong. >> has stronger precedence than & operator.
So we has to use () to group (op & 0F000) and the like.
I'd like to have a lint about this.

Categories (optional)

  • Kind: clippy::correctness

Drawbacks

None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-lintArea: New lintsT-ASTType: Requires working with the ASTgood-first-issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions