rust-lang / rust-lang/rust-clippy

extra_unused_type_parameters cannot be applied if fn is used

Open
#10,633 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-suggestion-causes-error
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.