rust-lang / rust-lang/rust-clippy

Unused generic parameter

Open
#4,610 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint L-complexity L-unnecessary
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

I ended up with a weird case of unused generic parameter that was not detected by the compilation (like it usually is) and that clippy didn't saw either. I'm not sure why but I've been able to craft a Minimal Example (or at least, I was not able to remove any part without the compiler to yell at me).

trait Foo {                   
    fn f();                
}                             
struct Bar;                   
                              
impl<'a> Foo for &'a Bar {    
    fn f() {               
        println!("foobar");   
    }                         
}                             
                              
fn my_func<H>()               
where                         
    for<'a> &'a H: Foo,       
{                             
    println!("Hello, world!");
}                             
                              
fn main() {                   
    my_func();                
}                             

In the above example, the function my_func has a generic parameter H that is never used and neither the compiler nor clippy is mentioning it.

Looking for other related issues, I've found #877 but the bug has been fixed. And like in #877, it might be a use case for rustc directly, I'm not sure.

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 minimal Rust example in the issue and run it with the reported compiler and Clippy versions, checking whether either reports the unused generic parameter. Compare the behavior with related issue #877, then determine whether the missing diagnostic belongs in rustc or Clippy; done means the example is correctly diagnosed with an appropriate regression test.

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
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.