Skip to content

Built in format macro should emit a warning when named arguments are used positionally #98466

@PrestonFrom

Description

@PrestonFrom

Michale Gattozzi identified this on twitter with a compelling sample:

fn main() {
    let mut _x: isize;
    let mut _y = (_x = 2) == (_x = 2);
    println!("{}", _x = 5);
    println!("{}", _x);
}

This prints

5
2

Which is potentially surprising, since it's not immediately obvious that the _x in the println macro is acting like a named argument.

It would be useful to emit either a warning or an error so that named arguments that are used only based on position are identified to avoid causing confusion, since to a reader it looks like an assignment.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions