]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs
Rollup merge of #107114 - Erk-:add-absolute-note-to-path-join, r=m-ou-se
[rust.git] / tests / ui / async-await / multiple-lifetimes / ret-impl-trait-one.rs
1 // edition:2018
2
3 // Test that a feature gate is needed to use `impl Trait` as the
4 // return type of an async.
5
6 trait Trait<'a> { }
7 impl<T> Trait<'_> for T { }
8
9 // Fails to recognize that both 'a and 'b are mentioned and should thus be accepted
10 async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
11     //~^ ERROR lifetime may not live long enough
12     (a, b)
13 }
14
15 // Only `'a` permitted in return type, not `'b`.
16 async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
17     //~^ ERROR captures lifetime that does not appear in bounds
18     (a, b)
19 }
20
21 // As above, but `'b: 'a`, so return type can be inferred to `(&'a u8,
22 // &'a u8)`.
23 async fn async_ret_impl_trait2<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a>
24 where
25     'b: 'a,
26 {
27     (a, b)
28 }
29
30 fn main() {
31 }