- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The suggestion that rustc gives is incorrect and seems to not take into account what characters are in the format argument.
I tried this code:
println!("hello {:?}", world = "world");I expected to see this happen:
  |
2 |     println!("hello {:?}", world = "world");
  |                     ----   ^^^^^ this named argument is referred to by position in formatting string
  |                     |
  |                     this formatting argument uses named argument `world` by position
  |
  = note: `#[warn(named_arguments_used_positionally)]` on by default
help: use the named argument by name to avoid ambiguity
  |
2 |     println!("hello {world:?}", world = "world");
  |                      ~~~~~
Instead, this happened:
  |
2 |     println!("hello {:?}", world = "world");
  |                     ----   ^^^^^ this named argument is referred to by position in formatting string
  |                     |
  |                     this formatting argument uses named argument `world` by position
  |
  = note: `#[warn(named_arguments_used_positionally)]` on by default
help: use the named argument by name to avoid ambiguity
  |
2 |     println!("hello {world}", world = "world");
  |                      ~~~~~
Meta
Using beta.2/nightly
rustc --version --verbose:
rustc 1.65.0-nightly (40336865f 2022-08-15)
binary: rustc
commit-hash: 40336865fe7d4a01139a3336639c6971647e885c
commit-date: 2022-08-15
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.