RS.CLIPPY.NEEDLESS_BITWISE_BOOL

Boolean expressions that use bitwise rather than lazy operators

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: needless_bitwise_bool. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for usage of bitwise and/or operators between booleans, where performance may be improved by using a lazy and.

Why is this bad?

The bitwise operators do not support short-circuiting, so it may hinder code performance. Additionally, boolean logic "masked" as bitwise logic is not caught by lints like unnecessary_fold

Known problems

This lint evaluates only when the right side is determined to have no side effects. At this time, that determination is quite conservative.

Example

let (x,y) = (true, false);
if x & !y {} // where both x and y are booleans

Use instead:

let (x,y) = (true, false);
if x && !y {}