Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint nonminimal-bool: suggests current code #4890

Closed
mvuets opened this issue Dec 8, 2019 · 2 comments
Closed

Lint nonminimal-bool: suggests current code #4890

mvuets opened this issue Dec 8, 2019 · 2 comments

Comments

@mvuets
Copy link

mvuets commented Dec 8, 2019

I've run into a boolean expression that Clippy marks as clippy::nonminimal-bool, however the suggested rewrite is exactly the same as the current code. Seems like a minor false positive bug to me.

Minimal reproducible example:

fn main() {
    let (d1, d2, d3) = (2, 4, 4);
    let _f = d1 == d2 && d2 != d3 || d1 != d2 && d2 == d3;
}

Clippy output:

$ cargo clippy -- -D clippy::nonminimal-bool
    Checking nonminbool v0.1.0 (/home/mvuets/tmp/nonminbool)
error: this boolean expression can be simplified
 --> src/main.rs:3:14
  |
3 |     let _f = d1 == d2 && d2 != d3 || d1 != d2 && d2 == d3;
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d1 == d2 && d2 != d3 || d1 != d2 && d2 == d3`
  |
  = note: requested on the command line with `-D clippy::nonminimal-bool`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
# -- snip --

FWIW, the lint description mentions "ignores short circuiting behavior" as a known problem, however I believe that's not the case here.

clippy --version: clippy 0.0.212 (4e7e71b 2019-10-11)

@ghost
Copy link

ghost commented Dec 8, 2019

Is this equivalent to let _f = (d1 == d2) ^ (d2 == d3)? 🤔

@flip1995
Copy link
Member

cc #4548

and @mikerite fixed this already in #4568. At least it doesn't trigger on the Playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants