You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, rustfmt combines unary minus with the expression it's being applied to. This can lead to ambiguity when it's followed by a method call on an integer literal. For example, -1.method() is parsed by rustc as -(1.method()) rather than (-1).method(). To reduce confusion, one might want to see a space between the unary minus and its operand, if the operand is a non-parethesized method invocation on a numeric literal. For example:
@chfogelman thanks for reaching out and offering to help. I've read through the discussion on rust-lang/rust#117155 (thanks for the link).
Right now I'm wondering if there's a clear consensus on what approach, if any, should be taken by rustfmt to resolve the ambiguity. I know you're proposing to add a space, but the issue description suggests rustfmt could stay true to the precedence rules and rewrite -1.method() as -(1.method()).
I think that needs to be cleared up before we move forward with any solution. Just my 2¢, but I think I'd lean towards -(1.method()) since there have been other instances where we needed to wrap expressions in parens to resolve bugs. For example, #5794 and #5842
At the same time I also want to note that this isn't really a bug caused by formatting, so changing how we rewrite the operand of a unary minus operator would need to be version gated or a new configuration option would need to be created where the default behavior is to leave -1.method() as is.
Currently,
rustfmt
combines unary minus with the expression it's being applied to. This can lead to ambiguity when it's followed by a method call on an integer literal. For example,-1.method()
is parsed by rustc as-(1.method())
rather than(-1).method()
. To reduce confusion, one might want to see a space between the unary minus and its operand, if the operand is a non-parethesized method invocation on a numeric literal. For example:This issue is motivated by: rust-lang/rust#117155
I'm happy to claim this and implement it, as long as maintainers think it's a good idea.
@rustbot claim
The text was updated successfully, but these errors were encountered: