Skip to content

Add disambiguating space after unary minus #5949

Open
@chfogelman

Description

@chfogelman

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:

-1;
-x;
-(x + y);
-x.y;
-x.method();
-(1.method());
// but
- 1.method();

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions