-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix output lifetime collection in needless_lifetimes #12456
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
Fix output lifetime collection in needless_lifetimes #12456
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.
Current commit results in a regression where more LTs are collected than they should be.
LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ||
| ^^ ^^ | ||
| | ||
help: elide the lifetimes | ||
| | ||
LL - fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ||
LL + fn multiple_inputs_output_not_elided<'b>(x: &u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ||
| | ||
| ^^ ^^ ^^ ^^ ^^ |
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 is wrong, it wrongly collects both 'a
and 'b
, should only elide 'a
LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { | ||
| ^^ ^^ | ||
| | ||
help: elide the lifetimes | ||
| | ||
LL - fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { | ||
LL + fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str { | ||
| | ||
| ^^ ^^ ^^ ^^ |
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.
'a
shouldn't be collected.
LL - fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} | ||
LL + fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {} | ||
| | ||
| ^^ ^^ ^^ ^^ |
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.
Same issue as above.
Hey @m-rph, this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation? @rustbot author |
@xFrednet yup. Need to find time. There's 5 issues that need to be addressed and will do all of them in 1 |
Okay, just here to poke you a bit ^^ Let me know if you need any help.
Sorry, couldn't resist after your comment :P |
The assignment was a test. I'm unassigning myself again. Thank you for the help! |
With Alejandra we discussed whether I could rewrite the lint given how old it was, both options are on the table. Seeing that I have accumulated a large collection of issues around |
Forgot about this. I will close. |
This is currently draft as I am unsure about how to go with fixing this. I don't completely understand the code D:, but I've identified the issue more or less.
The problem
In the following snippet
Clippy will suggest:
Which misses the 2 latter lifetimes.
I probed a bit into the implementation. The lifetimes of the output are collected via a walker. The implementation of the walker is identical for both input and output declaration.
The problem seems related to the truncation in
TyKind::OpaqueDef
rust-clippy/clippy_lints/src/lifetimes.rs
Lines 532 to 542 in 86717f2
Without the truncation, all lifetimes are collected, but going by
hir::DefId
, we have 4 different lifetimes (LTs) instead of 3. Going by span, we have 3 LTs.Removing the truncation and keeping only unique LT by their span causes something to break in the linting logic.
Update 1:
It seems that the issue is related to the defids of the LTs, as they can't be found in the allowed LTs.
Update 2:
Yup, using localdefid causes issues with opaque types. Using identifiers for any checks works better and the types are correlated selected. need to fix how the suggestions work to account for that, but otherwise it seems correct-ish.
fixes: #12085
fixes: #11291
r? @blyxyas