Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint for unused type parameters on functions #9240

Closed
mkrasnitski opened this issue Jul 24, 2022 · 6 comments · Fixed by #10028
Closed

Lint for unused type parameters on functions #9240

mkrasnitski opened this issue Jul 24, 2022 · 6 comments · Fixed by #10028
Assignees
Labels
A-lint Area: New lints

Comments

@mkrasnitski
Copy link
Contributor

mkrasnitski commented Jul 24, 2022

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) {
    // ..
}
@mkrasnitski mkrasnitski added the A-lint Area: New lints label Jul 24, 2022
@macovedj
Copy link
Contributor

@rustbot claim

@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented Jul 25, 2022

@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?

@macovedj
Copy link
Contributor

@rustbot release-assignment

@mkrasnitski
Copy link
Contributor Author

I appreciate it!

@mkrasnitski
Copy link
Contributor Author

@rustbot claim

@mkrasnitski mkrasnitski removed their assignment Oct 19, 2022
@mkrasnitski
Copy link
Contributor Author

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants