rust/tests/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
812 B
Rust
Raw Normal View History

// edition:2018
// Test that a feature gate is needed to use `impl Trait` as the
// return type of an async.
trait Trait<'a> { }
impl<T> Trait<'_> for T { }
2021-09-23 10:21:01 -05:00
// Fails to recognize that both 'a and 'b are mentioned and should thus be accepted
async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
2022-04-01 12:13:25 -05:00
//~^ ERROR lifetime may not live long enough
2021-09-23 10:21:01 -05:00
(a, b)
}
// Only `'a` permitted in return type, not `'b`.
async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
2021-09-23 10:21:01 -05:00
//~^ ERROR captures lifetime that does not appear in bounds
(a, b)
}
// As above, but `'b: 'a`, so return type can be inferred to `(&'a u8,
// &'a u8)`.
async fn async_ret_impl_trait2<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a>
where
'b: 'a,
{
(a, b)
}
fn main() {
}