rust-lang / rust-lang/rust-clippy
extra_unused_type_parameters cannot be applied if fn is used
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
.
Reproducer
I tried this code:
use std::backtrace::Backtrace;
#[inline(never)]
fn func_a() -> Backtrace {
func_b::<u8>()
}
#[inline(never)]
fn func_b<T>() -> Backtrace {
todo!();
}
fn main() {
eprint!("{}", func_a());
}
Clippy will suggest to remove the parameter here
warning: type parameter `T` goes unused in function definition
--> src/main.rs:8:10
|
8 | fn func_b<T>() -> Backtrace {
| ^^^ help: consider removing the parameter
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
= note: `#[warn(clippy::extra_unused_type_parameters)]` on by default
but we still have a call of that function with the parameter in the code which prevent cargo fix from applying the change smoothly :/
If we --broken-code it, rustc will error but we can't apply the suggestion of the error unfortunately
error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied
--> src/main.rs:5:5
|
5 | func_b::<u8>()
| ^^^^^^------ help: remove these generics
| |
| expected 0 generic arguments
|
note: function defined here, with 0 generic parameters
--> src/main.rs:8:4
|
8 | fn func_b() -> Backtrace {
| ^^^^^^
Could we make clippy walk through the function calls and suggest the removal of the param in an auto-applicable way there by itself?
Version
clippy 0.1.70 (87a2408 2023-04-11)
Additional Labels
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
Start with the extra_unused_type_parameters lint and the supplied func_a/func_b reproducer; run Clippy and cargo fix to observe the current suggestion and its failure. Trace how the lint reports the unused parameter and how the generic call is represented, then ensure the resulting diagnostic can be applied without leaving an invalid call, verified against this reproducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100