Skip to content

Fix some false positive in needless_lifetimes lint #452

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

Merged
merged 2 commits into from
Nov 14, 2015

Conversation

fhartwig
Copy link
Contributor

Fixes #417

The current lifetime-collecting visitor in needless_lifetimes doesn't take into account elided lifetimes on structs, enums or trait objects when collecting input and output lifetimes, which can lead to false positives. These changes fix it to consider these elided lifetimes as well.

One problem that I couldn't figure out is how to look up the definitions for type (and trait) aliases, which I would need to do to make this work with type aliases in function argument and return types as well. Any hints would be appreciated (although this PR should already strictly, and significantly, decrease the number of false positives).

@Manishearth
Copy link
Member

\o/ thanks! 🍰

reviewing now

TyPath(_, ref path) => {
self.collect_anonymous_lifetimes(path, ty);
},
_ => {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should bail if there is a TyObjectSum or TyPolyTraitRef, or a TyRptr of any kind around a trait (&Trait). Can be done in followup if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem with those? I've tested this on functions with trait object arguments, and I haven't noticed any problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an extra lifetime position with some strange rules around it IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Since I don't think this PR makes the situation regarding those any worse than it is right now (or does it?), I'd rather do this separately.

@Manishearth
Copy link
Member

This looks great to me, minor changes.

@Manishearth Manishearth self-assigned this Nov 11, 2015
@llogiq
Copy link
Contributor

llogiq commented Nov 11, 2015

I think we may want more test cases to see at a glance what works and what doesn't.

@fhartwig
Copy link
Contributor Author

@llogiq I'm happy to add more test cases. Any case in particular that you think is missing?

@llogiq
Copy link
Contributor

llogiq commented Nov 14, 2015

I think we could do with more tests where lifetimes are only partially specified. But we can do this in a followup.

r+

llogiq added a commit that referenced this pull request Nov 14, 2015
Fix some false positive in needless_lifetimes lint
@llogiq llogiq merged commit 1555eed into rust-lang:master Nov 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive for needless_lifetimes
3 participants