rust-lang / rust-lang/rust-clippy
Use & in pattern binding to remove noisy dereferencing of copy types.
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
The following:
fn main() {
let data = vec![1, 2, 3, 4, 5];
for i in &data {
if *i == 3 {
println!("Hmm!");
}
if *i == 2 {
println!("Ahh?");
}
if *i == 1 {
println!("Wut?!");
}
}
}
is less noisily expressed as:
fn main() {
let data = vec![1, 2, 3, 4, 5];
for &i in &data {
if i == 3 {
println!("Hmm!");
}
if i == 2 {
println!("Ahh?");
}
if i == 1 {
println!("Wut?!");
}
}
}
and it's obviously shorter than .iter().cloned().
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 locating the Clippy lint entry point and test structure for Rust pattern-related suggestions, then compare them with the examples in this issue. Done should include a lint that recognizes the noisy dereferencing form, suggests the & pattern binding, and verifies the shown cases without changing unrelated code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100