Skip to content

Bad suggestion: nonminimal_bool suggests replacing !cfg!(windows) with true. #1885

Closed
@kennytm

Description

@kennytm

Test case:

#![warn(nonminimal_bool)]
fn main() {
    let _ = !cfg!(windows);
}

Clippy will warn:

warning: this boolean expression can be simplified
 --> src/main.rs:3:13
  |
3 |     let _ = !cfg!(windows);
  |             ^^^^^^^^^^^^^^ help: try `true`
  |
note: lint level defined here
 --> src/main.rs:1:9
  |
1 | #![warn(nonminimal_bool)]
  |         ^^^^^^^^^^^^^^^
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#nonminimal_bool

The suggestion (try `true`) is wrong because the code will lose portability. Instead Clippy should suggest cfg!(not(windows)) or just don't emit the warning.


$ cargo clippy --version
0.0.143

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions