rust-lang / rust-lang/rust-clippy
Suggest to replace type parameter with impl
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
fn f<A: Sized>(x: A) can be replaced by fn(x: impl Sized), which is more readable and 99.9% sufficient for the purpose of specifying a parameter implementing a trait.
Advantage
More readable code (type is just after the variabile, no eyeballing between type parameters and argument types).
It is useful to have it as a lint because sometimes changes in the code make it possible to move a type parameter to impl, but the programmer might miss the opportunity.
Drawbacks
- Personal preference (some people might not like impl). In the case of return types impl has consequences (not being able to choose the return type) but in the case of function arguments this is not an issue.
- If the function has been turbofished, some editing is necessary as the parameter must be cast to the desired type instead.
Example
<code>
fn f<A: Sized>(a: A){
}
Could be written as:
<code>
fn f(a: impl Sized){
}
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
The issue proposes a Rust Clippy lint that suggests replacing a generic type parameter with an argument-position impl trait. No files, tests, or entry points are named; first locate the relevant Clippy lint infrastructure and related lint tests. Done means the lint handles the stated function-argument pattern and accounts for the turbofish and return-type drawbacks described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100