rust-clippy
rust-clippy copied to clipboard
Lint for unused type parameters on functions
What it does
Similar to extra_unused_lifetimes
, checks for unused type parameters on functions and warns that this is likely unintended, suggesting that they be removed. (Note: should this only apply to functions, or are there other places it could be run?)
Lint Name
extra_unused_type_parameters
Category
suspicious
Advantage
- Calling functions with unused type parameters requires adding a turbofish, since inferring them is impossible. The turbofish itself is useless other than to satisfy the compiler.
- If refactoring a function with a long signature and removing the use of generics, it's easy to miss removing the corresponding type parameter, especially if the function is
pub
and isn't used elsewhere. This accidentally exposes downstream users to the author's mistake, which is bad news.
Drawbacks
I can't think of any besides maybe the lint name, which might need some bikeshedding. Also, maybe a extra_unused_generics
lint could be introduced that implies both extra_unused_lifetimes
and extra_unused_type_params
?
Example
pub fn foo<T>(x: u8) {
// T unused in function body as well
// ..
}
Could be written as:
pub fn foo(x: u8) {
// ..
}
@rustbot claim
@macovedj If it's alright, I'd like to try implementing this myself (since I'd like to start contributing, also unsure if there can be multiple assignees), would you mind unclaiming?
@rustbot release-assignment
I appreciate it!
@rustbot claim
@rustbot claim