-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
9 changed files
with
230 additions
and
122 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,61 @@ | ||
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:12: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:34: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:46: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`. |
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.