-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add lint for unnecessary lifetime bounded &str return #13395
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @xFrednet (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
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.
I think maybe tcx.named_bound_var
should work for this? I'm not sure whether this would be before inference or not, but if it is a Ty
should give you all the info you need to generalize this to work outside of just &str
. Regions are erased in the typeck results, however tcx.fn_sig()
should still work.
Unfortunately, I don't think there would be any way to know if it's inferred nor can you get the span of a Ty
easily. Might be annoying. My first idea to get around that is to recurse over both the HIR Ty and Ty at once but that seems incredibly finicky; however, the solution should be regions regardless of how it's implemented.
I don't know how I would use |
Well, at the end of the day regions are practically lowered lifetimes (and scopes). It's not at all out of scope when the original issue cannot reliably be solved & generalized by parsing the source code alone, and by tracking lifetimes you're doing exactly what the compiler grants to you in such queries. |
Also now that I think about it, this could apply to |
Okay, I'll look into using |
Note, I'd definitely be fine with it being added if it's done this way, but it'll be harder to update + it'd be easier to rewrite it anyway
|
I have tried both dbg!(cx.tcx.named_bound_var(ret_hir_ty.hir_id)); and dbg!(cx.tcx.named_bound_var(inner_hir_ty.hir_id)); and they both always return |
@Centri3 since you already looked at this, do you want to take over the review? |
In specific I'm fairly sure you'll need the |
r? Centri3 |
Unfortunately looking closely at the implementation of it I don't know if |
How about we land this, then if you want you can improve it via lifetime stuff? As is, this doesn't add any false positives (to my knowledge) and is simply a little limited in what it lints (which is better than the not linting at all currently) |
☔ The latest upstream changes (presumably #13322) made this pull request unmergeable. Please resolve the merge conflicts. |
2115c9b
to
a2f50c1
Compare
Hey, @Centri3, just double checking you saw the comment above? Nearly been a month. |
I don't have the time at the moment unfortunately. I'll reroll |
☔ The latest upstream changes (presumably #13334) made this pull request unmergeable. Please resolve the merge conflicts. |
a2f50c1
to
7726593
Compare
7726593
to
b62d262
Compare
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Closes #305.
Currently implemented with a pretty strong limitation that it can only see the most basic implicit return, but this should be fixable by something with more time and brain energy than me. Cavets from #13388 apply, as I have not had a review on my clippy lints yet so am pretty new to this.