Skip to content

Incorrect suggestion with named_arguments_used_positionally lint #99265

Closed
@compiler-errors

Description

@compiler-errors

Code:

fn main() {
    println!("{b} {}", a=1, b=2);
}

The current output is:

warning: named argument `a` is not used by name
 --> /home/michael/test.rs:2:24
  |
2 |     println!("{b} {}", a=1, b=2);
  |               ---      ^ this named argument is only referred to by position in formatting string
  |               |
  |               this formatting argument uses named argument `a` by position
  |
  = note: `#[warn(named_arguments_used_positionally)]` on by default
help: use the named argument by name to avoid ambiguity
  |
2 |     println!("{a} {}", a=1, b=2);
  |               ~~~

Ideally it would look like:

  = note: `#[warn(named_arguments_used_positionally)]` on by default
help: use the named argument by name to avoid ambiguity
  |
2 |     println!("{b} {a}", a=1, b=2);
  |                    +
  1. The suggestion is not exactly correct. Instead of replacing the first named arg with the suggestion, we should replace the first implicitly positional argument.
  2. It would also be nice if we could tighten the span on the structured suggestion (see ~~~ -> + in the before and after)

Metadata

Metadata

Assignees

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