Description
I recently posted a thread on Rust Users when I was tripped up by this piece of code
if a >- 150 {
It's a simple typo (it should be >=
), but quite difficult to spot. It's not currently warned on by clippy.
A user on the thread did point out that the current behaviour is similar to what happens in other languages, and is not in fact ambiguous with respect to precedence, however, I wondered if people think it worth a lint? It took me an hour or so to find this error.
I can think of two 'problems' with the above that could be converted to a lint:
- The
-
should not be separated from the literal >-
is not a valid operator.
Of the two, the first is probably a better candidate, as I know there is a tendency for some programmmers to eschew whitespace when writing mathematial expressions making things such as if a>-150 {
or x*x>90
quite common (perhaps more so in C than in Rust).
The title says unary negation, but I guess + 200
ought to be considered as well.