-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-grammarArea: The grammar of RustArea: The grammar of RustA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.
Description
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
jhorstmann, jdahlstrom, ChayimFriedman2, tessob, tgross35 and 1 morekennytm
Metadata
Metadata
Assignees
Labels
A-grammarArea: The grammar of RustArea: The grammar of RustA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.