-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rust Reference documents operator associativity incorrectly #34386
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
Comments
/cc @rust-lang/lang , is this intentional? if so, I will fix the docs |
Yes, it is. I believe it has to do with how |
It actually does parse, even after the chained comparison error, and produces the expected type error :) |
@steveklabnik it's complicated, as the parser does technically parse Chances are that section was written before the chained comparisons error was implemented. |
And those error messages should be suppressed. |
This appears to be a documentation issue, closing in favor of an issue on the reference: https://github.com/rust-lang-nursery/reference. |
In section 7.2.12.8 "Operator precedence", the Rust reference says, "Operators at the same precedence level are evaluated left-to-right." I assume this is intended to mean that the binary operators are all left-associative.
However, the comparison operators (
==
!=
<
>
<=
>=
) are apparently non-associative, requiring explicit parentheses if you want to apply one to the result of another, as in(2 < 3) == true
. (That's a silly example, but I have in the past found utility in expressions like(a < b) != (c < d)
.)I think the implemented behavior is both reasonable and a good idea, so this is just a documentation bug, but I'm not really sure how to fix the documentation to be clear.
The text was updated successfully, but these errors were encountered: