fix(resolve): Warn on Self-Type Lifetime Elision for Non-Self Types#153692
Open
TKanX wants to merge 4 commits intorust-lang:mainfrom
Open
fix(resolve): Warn on Self-Type Lifetime Elision for Non-Self Types#153692TKanX wants to merge 4 commits intorust-lang:mainfrom
Self Types#153692TKanX wants to merge 4 commits intorust-lang:mainfrom
Conversation
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
Collaborator
|
Some changes occurred in compiler/rustc_hir/src/attrs |
Contributor
|
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
This comment has been minimized.
This comment has been minimized.
rust-bors bot
pushed a commit
that referenced
this pull request
Mar 18, 2026
…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.
Contributor
Collaborator
|
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.
Contributor
|
@TKanX: 🔑 Insufficient privileges: not in try users |
Contributor
|
@bors try |
This comment has been minimized.
This comment has been minimized.
rust-bors bot
pushed a commit
that referenced
this pull request
Mar 19, 2026
…e-match, r=<try> fix(resolve): Warn on Self-Type Lifetime Elision for Non-`Self` Types
Contributor
Contributor
|
@craterbot check |
Collaborator
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Contributor
|
☔ The latest upstream changes (presumably #154123) made this pull request unmergeable. Please resolve the merge conflicts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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