rust-lang / rust-lang/rust-clippy
`uninlined_format_args` main error message doesn't take specific macro into account
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The first error message for uninlined args references the format! macro, even when it's not the format! macro that's being invoked.
Reproducer
I tried this code (playground):
pub fn foo(mut w: impl std::io::Write) -> std::io::Result<()> {
let x = 5;
write!(w, "{}", x)?;
Ok(())
}
I expected to see this happen: a warning about the use of a variable that could be inlined in write!
Instead, this happened: a warning about the use of a variable that could be inlined in format!
warning: variables can be used directly in the `format!` string
--> src/lib.rs:3:5
|
3 | write!(w, "{}", x)?;
| ^^^^^^^^^^^^^^^^^^
|
= 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 - write!(w, "{}", x)?;
3 + write!(w, "{x}")?;
|
Version
clippy: 0.1.66 (2022-10-24 758f196)
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the uninlined_format_args lint entry point and reproduce the write! example from the issue. The change is complete when the diagnostic names the invoked macro instead of always referring to format!, while preserving the suggested {x} rewrite.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100