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 intorust-lang:mainfrom
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? |
Co-authored-by: lcnr <rust@lcnr.de> Co-authored-by: Michael Goulet <michael@errs.io>
f6ec003 to
dfcd644
Compare
dfcd644 to
805f449
Compare
…e-match, r=<try> fix(resolve): Warn on Self-Type Lifetime Elision for Non-`Self` Types
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
|
Reminder, once the PR becomes ready for a review, use |
52625a2 to
5d87eb2
Compare
This comment has been minimized.
This comment has been minimized.
5d87eb2 to
347424a
Compare
This comment has been minimized.
This comment has been minimized.
347424a to
ddda958
Compare
This comment has been minimized.
This comment has been minimized.
…deny for crater run (WILL BE REVERTED) Co-authored-by: Travis Cross <tc@traviscross.com>
ddda958 to
e46d6c7
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
@TKanX: 🔑 Insufficient privileges: not in try users |
|
@bors try |
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 check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
☔ The latest upstream changes (presumably #154123) made this pull request unmergeable. Please resolve the merge conflicts. |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
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