Skip to content

verbose_bit_mask is questionable #5633

Closed
@mahkoh

Description

@mahkoh

Consider the following:

pub const fn WTERMSIG(s: c::c_int) -> c::c_int {
    s & 0x7f
}

pub const fn WIFEXITED(s: c::c_int) -> bool {
    s & 0x7f == 0 //   <--- try: `s.trailing_zeros() >= 7`
}

The documentation for verbose_bit_mask has the following example:

x.trailing_zeros() > 4 is much clearer than x & 15 == 0

But this statement is wrong in the general case. Code such as x & 15 is often accompanied by other bit-fiddling to extract certain parts of the integer such as in the example above. Using trailing_zeros in one place and & 15 in the other makes the code as a whole much less clear.

verbose_bit_mask should be disabled by default.

cc @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    good 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