Skip to content

needless_lifetimes ignores trait bounds #292

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

Closed
Manishearth opened this issue Sep 3, 2015 · 6 comments · Fixed by #1672
Closed

needless_lifetimes ignores trait bounds #292

Manishearth opened this issue Sep 3, 2015 · 6 comments · Fixed by #1672
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-AST Type: Requires working with the AST

Comments

@Manishearth
Copy link
Member

fn foo<'a, T: Foo<'a>>(&'a u8, T) will hit the lint. It shouldn't, whenever we have lifetimes in trait bounds we should bail.

@Manishearth Manishearth added C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-AST Type: Requires working with the AST labels Sep 3, 2015
@Manishearth
Copy link
Member Author

@fhartwig
Copy link
Contributor

I think this should be re-opened. It's not really the same problem as #417, even though they're both false positives. #417 is basically about mis-counting input and output lifetimes, while the problem here is that you're not allowed to elide lifetimes in trait bounds.

@llogiq
Copy link
Contributor

llogiq commented Mar 2, 2016

I'd like to add that we still have false positives even after #599 – The followig (from rust-bio) is still linted:

pub fn find_all<'a, I: Iterator<Item=&'a u8>>(&'a self, text: I) -> Matches<I> {
    Matches { shiftand: self, active: 0, text: text.enumerate() }
}

@dtolnay
Copy link
Member

dtolnay commented Apr 7, 2017

Users of Serde are going to start hitting this really badly in the next release as we are adding a lifetime to the Deserializer trait.

fn f<'de, D: Deserializer<'de>>(deserializer: D) -> Result<F, D::Error> { /* ... */ }

It would be great to fix this before Serde 1.0.

@dtolnay
Copy link
Member

dtolnay commented Apr 8, 2017

@mcarton for whatever reason that is not the same. In particular:

trait WithLifetime<'a> {}

fn trait_bound<'a, T: WithLifetime<'a>>() { unimplemented!() }
warning: explicit lifetimes given in parameter types where they could be elided
 --> src/main.rs:3:1
  |
3 | fn trait_bound<'a, T: WithLifetime<'a>>() { unimplemented!() }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(needless_lifetimes)] on by default
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#needless_lifetimes

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 E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-AST Type: Requires working with the AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants