fix(resolve): Warn on Self-Type Lifetime Elision for Non-Self Types#153692
fix(resolve): Warn on Self-Type Lifetime Elision for Non-Self Types#153692TKanX wants to merge 4 commits into
Self Types#153692Conversation
7f7909c to
9922812
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ea23a3d to
7e85048
Compare
This comment has been minimized.
This comment has been minimized.
7e85048 to
7a90db6
Compare
|
Some changes occurred in compiler/rustc_hir/src/attrs |
|
before discussing this in a lang meeting, can you extend the PR description a bit to summarize the reasoning and discussion behind this? |
dfcd644 to
805f449
Compare
|
@rfcbot fcp concern should-example-cases-without-lifetimes |
|
@rfcbot reviewed |
Co-authored-by: lcnr <rust@lcnr.de> Co-authored-by: Michael Goulet <michael@errs.io>
…deny for crater run (WILL BE REVERTED) Co-authored-by: Travis Cross <tc@traviscross.com>
e46d6c7 to
1d914f5
Compare
|
This PR modifies |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
@bors try TODO: |
This comment has been minimized.
This comment has been minimized.
…e-match, r=<try> fix(resolve): Warn on Self-Type Lifetime Elision for Non-`Self` Types
|
@craterbot run mode=check-only crates=https://crater-reports.s3.amazonaws.com/pr-153692/retry-regressed-list.txt p=1 |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
Can the concern be resolved now? |
|
Looking at the crater results, two other cases stand out to me:
What are your thoughts on excluding these cases as well? |
|
☔ The latest upstream changes (presumably #157376) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@rustbot author |
View all comments
Summary
FCW lint
self_lifetime_elision_not_applicable: fires when aselfparameter contains&but does not syntactically containSelf.Tracking: #140611
Context
Self-type lifetime elision in
rustc_resolverelies on a name-matching hack (is_self_ty) that shallow-comparesResvalues between the self parameter type and the impl self type. As @compiler-errors identified in #140611, this hack cannot see through type aliases (differentRes) and only fires forStruct|Union|Enum|PrimTyimpls (excludesTyAlias). When it misses,find_lifetime_for_selfreturnsEmpty, self-elision silently fails, and a later parameter's lifetime may leak into the return type.@lcnr proposed restricting self-elision to genuine
Selfand FCW'ing everything else. This PR implements that.Behavior
impl Alias { fn f(self: &W) -> &() }'_impl Alias { fn f(self: &Alias) -> &() }'_impl Alias { fn f(&self) -> &() }impl W { fn f(self: &W) -> &() }impl W { fn f(self: &Alias) -> &() }'_impl W { fn f(&self) -> &() }A follow-up PR will remove the hack after a warning period.
r? @lcnr
cc @compiler-errors @traviscross