rust-lang / rust-lang/rust-clippy

Warn about unused named parameter in format strings

Open
#9,027 1 comment 0 reactions 1 assignee View on GitHub

@miam-miam is already working on this.

Since Jun 20, 2022.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Very few beginners know that named parameters can be used in format strings. (https://doc.rust-lang.org/std/fmt/index.html#named-parameters) This can often lead to great confusion as it looks like you are setting the variable to that value.

Additionally since you can now capture identifiers in format strings, named parameters will become less and less common. As such this new lint warns if a named parameter goes unused.

Lint Name

unused_named_parameter

Category

suspicious

Advantage
  • Removes redundant code
  • Prevents named parameters from being confused with an assignment such as print!("{}", x = x+1)
Drawbacks

No response

Example
println!("{}", x = 10);

Could be written as:

println!("{}", 10);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.