Two comparisons of the same value with constants are joined so that the result is always false or always true
What it finds
x > 10 && x < 5 is false for every x, and x < 5 || x > 3 true for every x: the ranges of the two comparisons do not overlap, or cover everything. Such a condition usually has a bound or an operator swapped. The rule looks at && and || whose operands both compare the same simple name or member with an integer literal, with <, <=, >, >=, == or !=; it treats the values as real numbers, so it never relies on the variable being an integer.
From the rule's source, impossible_range.rs.
class Ranges{ bool Never(int x) => x > 10 && x < 5;tx0 reports: x > 10 && x < 5 is always false bool Always(int x) => x < 5 || x > 3;tx0 reports: x < 5 || x > 3 is always true bool Inside(int x) => x > 0 && x < 10; bool Outside(int x) => x < 0 || x > 10; bool Both(int x) => x == 1 && x == 2;tx0 reports: x == 1 && x == 2 is always false bool Either(int x) => x != 1 || x != 2;tx0 reports: x != 1 || x != 2 is always true bool Edge(int x) => x >= 5 && x <= 5;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/csharp:impossible-range" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:impossible-range] reason="..."tx0 explain tx0/csharp:impossible-range shows the same in the terminal. Found a false positive? Report it.