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

Unused generic parameter #4610

Open
woshilapin opened this issue Oct 2, 2019 · 3 comments
Open

Unused generic parameter #4610

woshilapin opened this issue Oct 2, 2019 · 3 comments
Labels
A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group L-unnecessary Lint: Warn about unnecessary code

Comments

@woshilapin
Copy link
Contributor

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.

@sinkuu
Copy link
Contributor

sinkuu commented Oct 7, 2019

AFAIK rustc never warns against unused type parameters on functions.

fn foo<T>() {} // No warning against `T`

@woshilapin
Copy link
Contributor Author

Indeed, thank you for the precision. Then it might be a good case for clippy?

@flip1995 flip1995 added L-complexity Lint: Belongs in the complexity lint group L-unnecessary Lint: Warn about unnecessary code A-lint Area: New lints labels Oct 8, 2019
@basil-cow
Copy link
Contributor

I would like to tackle this, no promises though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group L-unnecessary Lint: Warn about unnecessary code
Projects
None yet
Development

No branches or pull requests

4 participants