Suggested lint for numeric literals with leading unary negation #4228
Labels
A-lint
Area: New lints
good-first-issue
These issues are a good way to get started with Clippy
L-style
Lint: Belongs in the style lint group
I recently posted a thread on Rust Users when I was tripped up by this piece of code
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:
-
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 {
orx*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.The text was updated successfully, but these errors were encountered: