-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stabilize anonymous_lifetime_in_impl_trait
- Loading branch information
Showing
7 changed files
with
225 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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.