Closed
Description
openedon Oct 25, 2023
This came up here but I am pretty sure I ran into this before: Rust parses -5.5f32.method()
as -(5.5f32.method())
. I don't know if that is the parsing result that anyone expects, I certainly would never expect it -5.5f32
is a float literals, and that is what I want to apply the method to, I never even considered that the compiler might interpret this as a unary minus applied to the method result.
Assuming that we cannot change the parser, I think we should spend some effort defending against the possible confusion here. For instance:
- lint against
-5.5f32.method()
(suggesting to write-(5.5f32.method())
if that's really what one meant) - have rustfmt add the parentheses that make precedence explicit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment