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
11.43k stars 1.54k forks source link

Behavioral regression in eq_op #11640

Open ofek opened 1 year ago

ofek commented 1 year ago

Summary

Lint: https://rust-lang.github.io/rust-clippy/master/index.html#/eq_op

It appears that now checks occur after evaluation of environment variables

Version known to work correctly:

❯ cargo clippy --version
clippy 0.1.70 (90c54180 2023-05-31)

Output:

error: equal expressions as operands to `==`
   --> src/app.rs:104:5
    |
104 |     env!("PYAPP_DISTRIBUTION_PIP_AVAILABLE") == "1"
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op
    = note: `#[deny(clippy::eq_op)]` on by default

error: equal expressions as operands to `==`
  --> src/commands/self_cmd/metadata.rs:10:18
   |
10 | #[command(hide = env!("PYAPP_EXPOSE_METADATA") == "0")]
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

error: equal expressions as operands to `==`
 --> src/commands/self_cmd/pip.rs:8:18
  |
8 | #[command(hide = env!("PYAPP_EXPOSE_PIP") == "0", disable_help_flag = true)]
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

error: equal expressions as operands to `==`
 --> src/commands/self_cmd/python.rs:8:18
  |
8 | #[command(hide = env!("PYAPP_EXPOSE_PYTHON") == "0", disable_help_flag = true)]
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

error: equal expressions as operands to `==`
 --> src/commands/self_cmd/python_path.rs:8:18
  |
8 | #[command(hide = env!("PYAPP_EXPOSE_PYTHON_PATH") == "0")]
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op

Reproducer

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8da4aa4e55400c911f26f2f17787bf3f

Version

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Additional Labels

No response

maurer commented 11 months ago

This issue hit us in real code - this build-time debuggability check did not trigger the lint on debug builds, but did when we went to produce user builds.

It would definitely be preferable if eq_op did not consider build-time-varying-expressions (cfg predicates, environment variables, includes, etc) did not count as their expanded variant for purposes of this lint.