-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.I-types-nominatedNominated for discussion during a types team meeting.Nominated for discussion during a types team meeting.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamneeds-craterThis change needs a crater run to check for possible breakage in the ecosystem.This change needs a crater run to check for possible breakage in the ecosystem.
Description
In reviewing a test case for,
- Add a new
mismatched-lifetime-syntaxes
lint #138677- (Which is part of Split elided_lifetime_in_paths into finer-grained lints #120808.)
I was led to the following oddity:
pub struct W<'a>(&'a ());
pub type Alias<'a> = W<'a>;
impl<'a> Alias<'a> {
fn f1<'x>(self: &W<'a>, x: &'x ()) -> &() { x } //~ `'_ == 'x`, what?
fn f2<'x>(self: &Alias<'a>, x: &'x ()) -> &() { x } //~ `'_ == 'x`, what?
fn f3<'x>(&self, _: &'x ()) -> &() { self.0 } //~ OK.
}
impl<'a> W<'a> {
fn f4<'x>(self: &W<'a>, _: &'x ()) -> &() { self.0 } //~ OK.
fn f5<'x>(self: &Alias<'a>, x: &'x ()) -> &() { x } //~ `'_ == 'x`, what?
fn f6<'x>(&self, _: &'x ()) -> &() { self.0 } //~ OK.
}
This was noticed long ago in #60944 (comment), which is presumably when the test case was added, but I can't immediately find later discussion.
The Reference doesn't document this behavior. (The FLS, as best I can tell on a skim, does not document lifetime elision at all.)
If there's a good reason for this as the correct behavior, we should probably write this down in the Reference. Otherwise, I'm going to propose we agree to try to do away with this somehow, if possible, maybe over an edition.
@rustbot labels +C-discussion +T-lang +I-lang-nominated +A-lifetimes
cc @rust-lang/lang @ehuss
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.I-types-nominatedNominated for discussion during a types team meeting.Nominated for discussion during a types team meeting.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamneeds-craterThis change needs a crater run to check for possible breakage in the ecosystem.This change needs a crater run to check for possible breakage in the ecosystem.