You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would constitute an addition of two new formatting flags, {:e} and {:E} and corresponding traits (e.g LowerSci and UpperSci). Here's the output I envision based on how Rust handles floating point and signs today. Notably, this differs from how C does it (Rust already differs from C, see #1375):
Duplicate of #6593. (FWIW, I'm personally not keen doing this with new format specifiers, when we can just use newtype structs; others may differ in this opinion.)
…sons, 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`]
This would constitute an addition of two new formatting flags,
{:e}
and{:E}
and corresponding traits (e.gLowerSci
andUpperSci
). Here's the output I envision based on how Rust handles floating point and signs today. Notably, this differs from how C does it (Rust already differs from C, see #1375):The text was updated successfully, but these errors were encountered: