Skip to content

Lint for unused type parameters on functions #9240

Closed
@mkrasnitski

Description

@mkrasnitski

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

complexity

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) {
    // ..
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions