rust-lang / rust-lang/rust-clippy
fp uninlined-format-args + ref-binding-to-reference
Open
Nobody has claimed this yet.
C-bug
I-false-positive
I-suggestion-causes-error
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
These lints together break the code
Lint Name
No response
Reproducer
I tried this code:
#![allow(dead_code)]
struct ST3<'a>(&'a i32); // With lifetime parameter
impl<'a> ST3<'a> {
fn ctor(v: &'a i32) -> Self {
Self(v)
}
fn pattern(self) {
let Self(ref v) = self;
println!("{}", v);
}
}
fn main() {}
I saw this happen:
cargo clippy --fix -- -Wclippy::uninlined-format-args -Wclippy::ref-binding-to-reference
after fixes were automatically applied the compiler reported errors within these files:
* src/main.rs
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag
The following errors were reported:
error: argument never used
--> src/main.rs:13:25
|
13 | println!("{v}", &v);
| ----- ^^ argument never used
| |
| formatting specifier missing
error: aborting due to previous error
Original diagnostics will follow.
warning: variables can be used directly in the `format!` string
--> src/main.rs:13:9
|
13 | println!("{}", v);
| ^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
= note: requested on the command line with `-W clippy::uninlined-format-args`
help: change this to
|
13 - println!("{}", v);
13 + println!("{v}");
|
warning: this pattern creates a reference to a reference
--> src/main.rs:12:18
|
12 | let Self(ref v) = self;
| ^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ref_binding_to_reference
= note: requested on the command line with `-W clippy::ref-binding-to-reference`
help: try this
|
12 ~ let Self(v) = self;
13 ~ println!("{}", &v);
|
Version
rustc 1.67.0-nightly (e0098a5cc 2022-11-29)
binary: rustc
commit-hash: e0098a5cc3a87d857e597af824d0ce1ed1ad85e0
commit-date: 2022-11-29
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
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 with the reproducer in src/main.rs and run the shown cargo clippy command with both uninlined-format-args and ref-binding-to-reference enabled. Compare the individual fixes with the combined --fix result; done means the automatic fixes preserve valid formatting arguments and the example compiles without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100