Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PrestonFrom opened this issue Jun 24, 2022 · 2 comments · Fixed by #98580
Closed
Assignees

Comments

@PrestonFrom
Copy link
Contributor

PrestonFrom commented Jun 24, 2022

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.

@PrestonFrom
Copy link
Contributor Author

@rustbot claim

@Mark-Simulacrum
Copy link
Member

cc #45256 and #93415 which are previously open issues on this

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 14, 2022
Emit warning when named arguments are used positionally in format

Addresses Issue 98466 by emitting an error if a named argument
is used like a position argument (i.e. the name is not used in
the string to be formatted).

Fixes rust-lang#98466
@bors bors closed this as completed in 1219f72 Jul 14, 2022
github-actions bot pushed a commit to gnoliyil/fuchsia that referenced this issue Jul 17, 2022
Some old code was formatting a named variable but not reference the
name in the formatting string. This change adds the identifier to the
formatting string, but does not affect the behavior of the formatting. The new compiler warning was introduced in rust-lang/rust#98466

Bug: 104577

Change-Id: I7a19d1aa23a12fd116dfb5488f0c233cf24e3cb7
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/701186
Commit-Queue: Paul Faria <paulfaria@google.com>
Reviewed-by: Mitchell Kember <mkember@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants