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

named_arguments_used_positionally suggestion does not take into account debug displaying #100648

Closed
miam-miam opened this issue Aug 16, 2022 · 2 comments · Fixed by #100826
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@miam-miam
Copy link
Contributor

miam-miam commented Aug 16, 2022

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
@miam-miam miam-miam added the C-bug Category: This is a bug. label Aug 16, 2022
@vincenzopalazzo
Copy link
Member

vincenzopalazzo commented Aug 16, 2022

@rustbot label -C-bug +A-diagnostics +T-compiler

@vincenzopalazzo
Copy link
Member

@rustbot claim

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Aug 16, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 24, 2022
…with_positional_arg, r=TaKO8Ki

sugg: take into count the debug formatting

Closes rust-lang#100648

This PR will fix a suggestion error by taking into consideration also the `:?` symbol and act in a different way

`@rustbot` r? `@compiler-errors`

N.B: I did not find a full way to test the change, any idea?
@bors bors closed this as completed in f8e128f Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants