-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
impl Trait
Lifetime Elision
#43396
Comments
The ICE should not be fixed, but rather elision be disabled, unless someone can point me to an accepted RFC allowing this kind of elision. cc @rust-lang/lang |
So @cramertj and I discussed this over IRC today. The plan is to support elision as follows:
fn foo(x: &u32) -> impl Trait<'_> { ... } desugaring to something like: abstract type Foo<'a>: Trait<'a>;
fn foo(x: &u32) -> Foo<'_> { ... } To implement this, we have to first modify HIR lowerring to detect elided lifetimes when it is scraping the impl trait bounds for additional parameters. We can then add a special parameter (perhaps naming it Then we have to modify name resolution as follows. When we are lifetime-resolving the trait bounds ( rust/src/librustc/middle/resolve_lifetime.rs Line 496 in 833785b
we would insert an elision scope: rust/src/librustc/middle/resolve_lifetime.rs Lines 248 to 253 in 833785b
with rust/src/librustc/middle/resolve_lifetime.rs Lines 271 to 272 in 833785b
We will also insert a reference to the elided lifetime into the |
An example from #46565: struct Parent
{
children: Option<Vec<String>>
}
impl Parent {
pub fn children() -> impl Iterator<Item=&str> {
self.children.unwrap_or(Vec::new()).iter()
}
} |
Implement impl Trait lifetime elision Fixes #43396. There's one weird ICE in the interaction with argument-position `impl Trait`. I'm still debugging it-- I've left a test for it commented out with a FIXME. Also included a FIXME to ensure that `impl Trait` traits are caught under the lint in #45992. r? @nikomatsakis
The following ICEs:
fn foo(x: &bool) -> impl Into<&bool> { x }
The message is:
error: internal compiler error: /checkout/src/librustc_typeck/check/mod.rs:618: escaping regions in predicate Obligation(predicate=Binder(TraitPredicate(<_ as std::convert::Into<&bool>>)),depth=0) --> src/main.rs:6:21
.Should we explicitly disallow lifetime elision in
impl Trait
?The text was updated successfully, but these errors were encountered: