about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/example/alloc_system.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-06 17:20:07 +0000
committerbors <bors@rust-lang.org>2023-08-06 17:20:07 +0000
commit6a2c8a1e7bfe6cd4823cfd785c49af4afcb98180 (patch)
tree0f3df58038b850b8766c47c9b3c2da2997ebac05 /compiler/rustc_codegen_gcc/example/alloc_system.rs
parent5818225a89bfb8645cbf9c10c0d8a10c5b063d71 (diff)
parentd62804624441c2f7bf3de45cd2c9b5c411b2d6a6 (diff)
downloadrust-6a2c8a1e7bfe6cd4823cfd785c49af4afcb98180.tar.gz
rust-6a2c8a1e7bfe6cd4823cfd785c49af4afcb98180.zip
Auto merge of #10843 - MortenLohne:feat/double-const-comparisons, r=Centri3
New lints: `impossible_comparisons` and `redundant_comparisons`

Inspired by a bug we had in production, like all good lints ;)

Adds two lints for "double" comparisons, specifically when the same expression is being compared against two different constants.

`impossible_comparisons` checks for expressions that can never be true at all. Example:
```rust
status_code <= 400 && status_code > 500
```
Presumably, the programmer intended to write `status_code >= 400 && status_code < 500` in this case.

`redundant_comparisons` checks for expressions where either half has no effect. Example:
```rust
status_code <= 400 && status_code < 500
```

Works with other literal types like floats and strings, and *some* cases where the constant is more complex than a literal, see the tests for more.

**Limitations and/or future work:**
* Doesn't work if the LHS can have side-effects at all, for example by being a function call
* Only works for exactly two comparison expressions, so `x > y && x > z && x < w` won't get checked
* Doesn't check for comparison expressions combined with `||`. Very similar logic could be applied there.

changelog: New lints [`impossible_comparisons`] and [`redundant_comparisons`]
Diffstat (limited to 'compiler/rustc_codegen_gcc/example/alloc_system.rs')
0 files changed, 0 insertions, 0 deletions