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

How to resolve extra_unused_lifetimes? #4291

Closed
sunng87 opened this issue Jul 21, 2019 · 3 comments · Fixed by #4477
Closed

How to resolve extra_unused_lifetimes? #4291

sunng87 opened this issue Jul 21, 2019 · 3 comments · Fixed by #4477
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@sunng87
Copy link

sunng87 commented Jul 21, 2019

clippy -V: clippy 0.0.212 (b029042 2019-07-12)

I'm getting clippy warnings for unused lifetime in function definition like:

warning: this lifetime isn't used in the function definition
  --> src/helpers/helper_with.rs:13:13
   |
13 |     fn call<'_reg: '_rc, '_rc>(
   |             ^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes

The function is defined in a trait, and here in it's implementation some unused lifetimes in argument types were omitted and compiler think it's ok. However, removing these will cause compilation error that compiler finds the definition was incompatible with trait.

Also by prefixing the unused lifetimes with _ doesn't work for clippy.

So is there a recommended solution for this case other than add all lifetime specifiers to argument types?

@flip1995
Copy link
Member

I can't reproduce this on my machine. Also your link to the implementation isn't the function in the warning message.

Have you changed anything else? Can you push a reproducer in a separate branch/fork to the repo and link it here?

@sunng87
Copy link
Author

sunng87 commented Jul 23, 2019

Sorry, I fixed by adding lifetime to those types, which I don't think is a perfect fix. You can checkout tag 2.0.1 and reproduce.

The trait at 2.0.1:
https://github.com/sunng87/handlebars-rust/blob/2.0.1/src/helpers/mod.rs#L88

The impl:
https://github.com/sunng87/handlebars-rust/blob/2.0.1/src/helpers/helper_lookup.rs

@flip1995
Copy link
Member

Quite minimal reproducer:

#[derive(Debug)]
pub struct Foo<'a>(&'a std::marker::PhantomData<u8>);

#[derive(Debug)]
pub struct Bar<'a: 'b, 'b>(Foo<'a>, &'b std::marker::PhantomData<u8>);

trait LT {
    fn test<'a: 'b, 'b>(foo: &Foo<'a>, bar: &Bar<'a, 'b>);
}

pub struct Baz;

impl LT for Baz {
    fn test<'a: 'b, 'b>(_foo: &Foo, _bar: &Bar) {
        
    }
}

Playground

We shouldn't lint trait implementations

@flip1995 flip1995 added the C-bug Category: Clippy is not doing the correct thing label Jul 23, 2019
bors added a commit that referenced this issue Sep 2, 2019
Fix `extra_unused_lifetimes` false positive

Fixes #4291

changelog: Fix `extra_unused_lifetimes` false positive
@bors bors closed this as completed in 88750f9 Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants