rust-lang / rust-lang/rust-analyzer
`uninlined_format_args` auto-fix fails to apply
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
#![warn(clippy::uninlined_format_args)]
fn main() {
let x = 1;
let y = 2;
println!("{}, {}, {0}", x, y)
}
This produces a correct-looking clippy warning:
warning: variables can be used directly in the `format!` string
--> src/main.rs:6:3
|
6 | println!("{}, {}, {0}", x, y)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::uninlined_format_args)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: change this to
|
6 - println!("{}, {}, {0}", x, y)
6 + println!("{x}, {y}, {x}")
|
However, the Ctrl-. auto-fix (which says change this to: `x`, `y`, `x` ) does nothing when you select it. This only happens when numbered arguments are used to repeat a variable.
Also, the fix is only applicable within the span , x, y of the original code, even though the warning span covers the entire function call println!("{}, {}, {0}", x, y). This is annoying when using F8 to jump to the next error and then Ctrl-. to fix it - you have to find the span of the variables to be replaced before you can trigger the fix.
rust-analyzer version: 0.4.1239-standalone
rustc version: rustc 1.66.0-nightly (a6b7274a4 2022-10-10)
clippy version: clippy 0.1.66 (a6b7274 2022-10-10)
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
Reproduce the issue with the provided Rust snippet and the uninlined_format_args Clippy diagnostic, then trace rust-analyzer's Ctrl-. fix handling for numbered format arguments and its applicable span. Done means the fix applies to repeated variables and can be invoked from the full println! diagnostic span.
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
- 38/100