rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
10.89k stars 1.46k forks source link

`overly_complex_bool_expr` triggers wrongly #12689

Open bend-n opened 3 weeks ago

bend-n commented 3 weeks ago

Summary

#[allow(unreachable_code, clippy::never_loop, clippy::diverging_sub_expression)]
loop { _ = (break) || true; }

this triggers the overly_complex_bool_expr error, incorrectly, as it suggests loop { _ = true }.

Lint Name

overly_complex_bool_expr

Reproducer

I tried this code:

#[allow(unreachable_code, clippy::never_loop, clippy::diverging_sub_expression)]
loop { _ = (break) || true; }

I saw this happen:

error: this boolean expression contains a logic bug
 --> src/main.rs:3:12
  |
3 | loop { _ = (break) || true; }
  |            ^^^^^^^^^^^^^^^ help: it would look like the following: `true`
  |
help: this expression can be optimized out by applying boolean operations to the outer expression
 --> src/main.rs:3:12
  |
3 | loop { _ = (break) || true; }
  |            ^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#overly_complex_bool_expr
  = note: `#[deny(clippy::overly_complex_bool_expr)]` on by default

I expected to see this happen:

Version

rustc 1.79.0-nightly (ccfcd950b 2024-04-15)
binary: rustc
commit-hash: ccfcd950b333fed046275dd8d54fe736ca498aa7
commit-date: 2024-04-15
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Additional Labels

No response