Add diagnostic hint when or-ing values which may be missing an equality comparison #128132
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Rationale and extra context
I teach people software engineering who don't have a software engineering background, and have noticed that a surprising number of people try to write this kind of code (perhaps because in their head they're thinking "I need to check if x is 1 or 2" and "||" translates directly to "or", where in reality they need to be thinking "I need to check if x is 1 or x is 2".
This has come up often enough that I think it would be a useful hint to provide - as things stand, I haven't found a really easy way of guiding people to make this realisation themself other than just telling them, so the compiler hinting it to them feels useful.
It feels like this could be useful to trigger in any condition (i.e. place expecting a boolean) where:
||
==
(or possibly!=
comparison)||
has a type which is comparable to the LHS of the first==
(or perhaps, has the same type as the RHS of the first==
)Other cases
No response
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: