rust-lang / rust-lang/rust-clippy
Detect use of unnecessary `dyn` in function parameter
Open
Nobody has claimed this yet.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Scan for all uses of a function, and check if the &dyn T can be replaced by &impl T.
Advantage
- Avoid the overhead introduced by dynamic dispatch
Drawbacks
Code bloat and compile overhead.
Example
// A private trait that takes a dyn reference.
trait Trait {
fn f(writer: &mut dyn std::io::Write);
}
// Using that trait with concrete types.
fn use_trait(obj: impl Trait) {
obj.f(&mut Vec::new());
}
Could be written as:
trait Trait {
fn f(writer: &mut impl std::io::Write);
}
fn use_trait(obj: impl Trait) {
obj.f(&mut Vec::new());
}
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
No implementation file or test is named. Start by reviewing how rust-clippy registers lints and how existing lints inspect function parameters and their uses. Done means detecting eligible &dyn T parameters that can become &impl T, while accounting for the stated code-bloat and compile-overhead drawbacks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100