Skip to content

named_arguments_used_positionally suggestion does not take into account debug displaying #100648

Closed
@miam-miam

Description

@miam-miam

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

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions