rust-lang / rust-lang/rust-clippy
Unused type angle brackets, and/or unnecessary angle brackets
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
It would be nice if clippy could detect whether such type notations are not necessary, and the code would compile without them:
fn test<T: Neg>(x: T) -> T {
<T as Neg>::neg(x)
}
This would result in the following fixed code:
fn test<T: Neg>(x: T) -> T {
T::neg(x)
}
However, the vision here is that this could also detect "partial refactoring" options like the below, which would also fix to the same output:
fn test<T: Neg>(x: T) -> T {
<T>::neg(x)
}
Advantage
- Can help reduce code size and make code more understandable (for example, the resulting
T::neg(x)could potentially be modified by other lints intox.neg()or-xin the case of operator methods). - Can help make refactoring easier by letting the linter remove
<>if you just search-and-replaceas Trait>with>, rather than needing to use a regular expression.
Drawbacks
- The amount of type information needed for this is probably quite complicated, at least in the case of removing the
as Traitportion. - This is a pretty niche change that would probably require a lot of work.
Example
(your issue template is unable to determine that I already included examples)
Comparison with existing lints
Loads of "unnecessary X" lints exist in clippy, and so, this would fit right in.
Additional Context
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
The issue names no files, tests, or entry points. Begin by studying Clippy's existing unnecessary-X lints and the type information needed for the Rust examples; done means detecting both forms of unnecessary angle brackets and providing the described fixed code.
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