-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Do not propose to elide lifetimes if this causes an ambiguity #13929
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. Comments which are hopefully simple enough to fix.
488a230
to
e2ff1fb
Compare
type Result = ControlFlow<bool>; | ||
|
||
fn visit_lifetime(&mut self, lifetime: &Lifetime) -> Self::Result { | ||
ControlFlow::Break(lifetime.is_elided() || lifetime.is_anonymous()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently breaks on the first lifetime it finds. Meaning that (x: Cx<'_, 'tcx>)
would say it's anonymous, right?
It feels like this should only break if it finds a user-defined lifetime 🤔
Could you also add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but:
- when checking the output type, we don't care about the lifetime being anonymous (we just want to know if we have at least one lifetime)
- we check the input types only when the function supports lifetime elision, which is not the case here because we have at least two input lifetimes (
'_
and'tcx
)
Does that make sense? I've added a test, let me know if this is what you had in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It make sense, I didn't know that two LTs implied that they can't be elapsed
1455ca0
to
cadbe44
Compare
Some lifetimes in function return types are not bound to concrete content and can be set arbitrarily. Clippy should not propose to replace them by the default `'_` lifetime if such a lifetime cannot be determined unambigously.
cadbe44
to
c686ffd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you the update!
Roses are red,
Violets are blue,
This lint doesn't elide,
needed lifetimes anymore.
Silly me. @xFrednet changelog added. |
Some lifetimes in function return types are not bound to concrete content and can be set arbitrarily. Clippy should not propose to replace them by the default
'_
lifetime if such a lifetime cannot be determined unambigously.I added a field to the
LifetimeChecker
andUsage
to flag lifetimes that cannot be replaced by default ones, but it feels a bit hacky.Fix #13923
changelog: [
needless_lifetimes
]: remove false positives by checking that lifetimes can indeed be elided