rust-lang / rust-lang/rust-clippy
lint needless borrows in format args
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
This could probably be its own lint rather than an extension of needless_borrow (on the user facing side at least, so that we can allow/deny that specific part of the lint)
When passing args to format!() and and friends, we actually don't need to explicitly use a &borrow because we don't consume the object:
println!("{:?} {} {}", &a, &b, &c.display());
could as well be:
println!("{:?} {} {}", a, b, c.display());
as this code sample demonstrates:
pub fn main() {
let a = vec!['a'];
let b = "hello";
let c = std::path::PathBuf::from("/");
println!("{:?} {} {}", a, b, c.display());
std::mem::drop(a);
std::mem::drop(b);
std::mem::drop(c);
}
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 by reading the existing needless_borrow lint and the format-argument examples in this issue. Determine how a separate user-facing lint should recognize unnecessary borrows in format! and related macros; done means the lint can be independently allowed or denied and covers the demonstrated cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100