rust-lang / rust-lang/rust-clippy

uninlined_format_args is too strict around renamed args

Open
#10,247 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary

clippy suggests inlining a format arg that has been explicitly renamed

Lint Name

uninlined_format_args

Reproducer

I tried this code:

fn main() {
    let val = "World";
    println!("Hello, {name}!", name = val);
}

I saw this happen:

warning: variables can be used directly in the `format!` string
 --> src/main.rs:3:5
  |
3 |     println!("Hello, {name}!", name = val);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
  = note: `#[warn(clippy::uninlined_format_args)]` on by default
help: change this to
  |
3 -     println!("Hello, {name}!", name = val);
3 +     println!("Hello, {val}!");
  |

I expected to see this happen:

No warning

Version
rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: aarch64-apple-darwin
release: 1.67.0
LLVM version: 15.0.6
Additional Labels

No response

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.

Research direction

Start with the uninlined_format_args lint and reproduce the warning using the Rust snippet in the issue. Trace how the lint handles explicitly renamed arguments, then add a regression case so this form produces no warning and verify the existing diagnostic behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.