-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Stabilize anonymous_lifetime_in_impl_trait
#107378
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
trait Foo<T> { | ||
fn foo(&self, _: T) { } | ||
} | ||
|
||
trait FooBar<'a> { | ||
type Item; | ||
} | ||
|
||
mod foo { | ||
fn fun(t: impl crate::Foo<&u32>, n: u32) { | ||
t.foo(&n); | ||
//~^ ERROR `n` does not live long enough | ||
} | ||
} | ||
|
||
mod fun { | ||
fn fun(t: impl Fn(&u32), n: u32) { | ||
t(&n); | ||
} | ||
} | ||
|
||
mod iterator_fun { | ||
fn fun(t: impl Iterator<Item = impl Fn(&u32)>, n: u32) { | ||
for elem in t { | ||
elem(&n); | ||
} | ||
} | ||
} | ||
|
||
mod iterator_foo { | ||
fn fun(t: impl Iterator<Item = impl crate::Foo<&u32>>, n: u32) { | ||
for elem in t { | ||
elem.foo(&n); | ||
//~^ ERROR `n` does not live long enough | ||
} | ||
} | ||
} | ||
|
||
mod placeholder { | ||
trait Placeholder<'a> { | ||
fn foo(&self, _: &'a u32) {} | ||
} | ||
|
||
fn fun(t: impl Placeholder<'_>, n: u32) { | ||
t.foo(&n); | ||
//~^ ERROR `n` does not live long enough | ||
} | ||
} | ||
|
||
mod stabilized { | ||
trait InTrait { | ||
fn in_trait(&self) -> impl Iterator<Item = &u32>; | ||
} | ||
|
||
fn foo1(_: impl Iterator<Item = &u32>) {} | ||
fn foo2<'b>(_: impl crate::FooBar<'b, Item = &u32>) {} | ||
} | ||
|
||
fn main() { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
error[E0597]: `n` does not live long enough | ||
--> $DIR/impl-trait-lifetimes.rs:11:15 | ||
| | ||
LL | fn fun(t: impl crate::Foo<&u32>, n: u32) { | ||
| - has type `t` - binding `n` declared here | ||
LL | t.foo(&n); | ||
| ------^^- | ||
| | | | ||
| | borrowed value does not live long enough | ||
| argument requires that `n` is borrowed for `'1` | ||
LL | | ||
LL | } | ||
| - `n` dropped here while still borrowed | ||
|
||
error[E0597]: `n` does not live long enough | ||
--> $DIR/impl-trait-lifetimes.rs:33:22 | ||
| | ||
LL | fn fun(t: impl Iterator<Item = impl crate::Foo<&u32>>, n: u32) { | ||
| - binding `n` declared here | ||
LL | for elem in t { | ||
LL | elem.foo(&n); | ||
| ^^ borrowed value does not live long enough | ||
... | ||
LL | } | ||
| - `n` dropped here while still borrowed | ||
|
||
error[E0597]: `n` does not live long enough | ||
--> $DIR/impl-trait-lifetimes.rs:45:15 | ||
| | ||
LL | fn fun(t: impl Placeholder<'_>, n: u32) { | ||
| - has type `t` - binding `n` declared here | ||
LL | t.foo(&n); | ||
| ------^^- | ||
| | | | ||
| | borrowed value does not live long enough | ||
| argument requires that `n` is borrowed for `'1` | ||
LL | | ||
LL | } | ||
| - `n` dropped here while still borrowed | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
33 changes: 33 additions & 0 deletions
33
tests/ui/impl-trait/partial-anonymous-lifetime-in-impl-trait.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Incremental stabilization of `non-generic associated types` for non-generic associated types. | ||
|
||
mod stabilized { | ||
trait FooBar<'a> { | ||
type Item; | ||
} | ||
|
||
fn foo0(x: impl Iterator<Item = &u32>) { | ||
} | ||
|
||
fn foo1<'b>(_: impl FooBar<'b, Item = &u32>) { | ||
} | ||
} | ||
|
||
mod not_stabilized { | ||
trait FooBar<'a> { | ||
type Item; | ||
} | ||
|
||
trait LendingIterator { | ||
type Item<'a> | ||
where | ||
Self: 'a; | ||
} | ||
|
||
fn foo0(_: impl LendingIterator<Item<'_> = &u32>) {} | ||
//~^ ERROR `'_` cannot be used here | ||
//~| ERROR anonymous lifetimes in `impl Trait` are unstable | ||
|
||
fn foo1(_: impl FooBar<'_, Item = &u32>) {} | ||
} | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
tests/ui/impl-trait/partial-anonymous-lifetime-in-impl-trait.stderr
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0637]: `'_` cannot be used here | ||
--> $DIR/partial-anonymous-lifetime-in-impl-trait.rs:26:42 | ||
| | ||
LL | fn foo0(_: impl LendingIterator<Item<'_> = &u32>) {} | ||
| ^^ `'_` is a reserved lifetime name | ||
|
||
error[E0658]: anonymous lifetimes in `impl Trait` are unstable | ||
--> $DIR/partial-anonymous-lifetime-in-impl-trait.rs:26:49 | ||
| | ||
LL | fn foo0(_: impl LendingIterator<Item<'_> = &u32>) {} | ||
| ^ expected named lifetime parameter | ||
| | ||
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | fn foo0<'a>(_: impl LendingIterator<Item<'_> = &'a u32>) {} | ||
| ++++ ++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0637, E0658. | ||
For more information about an error, try `rustc --explain E0637`. |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.