-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch xor vs power confusion #4205
Comments
I'm curious: Is there a programming language where Since writing |
I think writing this with constants in base ten is highly suspicious and could be a regular or pedantic lint. Especially for |
The fact that I think raising 2 and 10 to a power is a much more common operation than xoring constant 2 or 10 with something.
xoring is all about bits, so the lint shouldn't apply to non-decimal notations (e.g. |
Found this issue after being linked to this GCC thread on the same topic https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90885 - possibly useful for additional context / comments 🙂 My initial reaction was "ha, that definitely sounds like an easy human error to make, and sounds exactly like one of those errors where rustc and/or clippy would go the extra mile in being magically helpful as they always are". I agree that this is probably a high-value lint to add, considering how easy it probably is to make this mistake (ref. ascii documentation etc), and the likelihood of intended behavior of xor vs exponentiation when dealing with decimal values, especially constants. EDIT: I'll give a try at implementing this 🙂 |
Commented in closed PR (as it was inactive). Would anybody mind me picking this up and pushing it across the finish line since it's been a while? |
Three inactive PR, cool! |
Really impressed this isn't solved yet, I got a lucky one! Edit: 3 pull requests before mine. Relevant XKCD |
In Haskell:
In Python ** is used. D language uses ^^. |
2x is often written in ASCII as 2^x, but in Rust this happens to xor the value instead of raising it to the power.
Apparently, people make that mistake, and so far it goes undetected:
https://twitter.com/johnregehr/status/1139302389612077056
The text was updated successfully, but these errors were encountered: