11// edition:2021
2+ // revisions: success failure
3+ //[success] check-pass
24
35#![ feature( return_position_impl_trait_in_trait) ]
46#![ allow( incomplete_features) ]
@@ -11,16 +13,25 @@ impl<T> Captures<'_> for T {}
1113trait Captures2 < ' a , ' b > { }
1214impl < T > Captures2 < ' _ , ' _ > for T { }
1315
14- pub trait AsyncTrait {
16+ trait AsyncTrait {
17+ #[ cfg( success) ]
1518 fn async_fn ( & self , buff : & [ u8 ] ) -> impl Future < Output = Vec < u8 > > ;
19+
20+ #[ cfg( success) ]
1621 fn async_fn_early < ' a : ' a > ( & self , buff : & ' a [ u8 ] ) -> impl Future < Output = Vec < u8 > > ;
22+
23+ #[ cfg( success) ]
1724 fn async_fn_multiple < ' a > ( & ' a self , buff : & [ u8 ] )
18- -> impl Future < Output = Vec < u8 > > + Captures < ' a > ;
25+ -> impl Future < Output = Vec < u8 > > + Captures < ' a > ;
26+
27+ #[ cfg( failure) ]
1928 fn async_fn_reduce_outlive < ' a , T > (
2029 & ' a self ,
2130 buff : & [ u8 ] ,
2231 t : T ,
2332 ) -> impl Future < Output = Vec < u8 > > + ' a ;
33+
34+ #[ cfg( success) ]
2435 fn async_fn_reduce < ' a , T > (
2536 & ' a self ,
2637 buff : & [ u8 ] ,
@@ -31,38 +42,49 @@ pub trait AsyncTrait {
3142pub struct Struct ;
3243
3344impl AsyncTrait for Struct {
45+ // Does not capture more lifetimes that trait def'n, since trait def'n
46+ // implicitly captures all in-scope lifetimes.
47+ #[ cfg( success) ]
3448 fn async_fn < ' a > ( & self , buff : & ' a [ u8 ] ) -> impl Future < Output = Vec < u8 > > + ' a {
35- //~^ ERROR return type captures more lifetimes than trait definition
3649 async move { buff. to_vec ( ) }
3750 }
3851
52+ // Does not capture more lifetimes that trait def'n, since trait def'n
53+ // implicitly captures all in-scope lifetimes.
54+ #[ cfg( success) ]
3955 fn async_fn_early < ' a : ' a > ( & self , buff : & ' a [ u8 ] ) -> impl Future < Output = Vec < u8 > > + ' a {
40- //~^ ERROR return type captures more lifetimes than trait definition
4156 async move { buff. to_vec ( ) }
4257 }
4358
59+ // Does not capture more lifetimes that trait def'n, since trait def'n
60+ // implicitly captures all in-scope lifetimes.
61+ #[ cfg( success) ]
4462 fn async_fn_multiple < ' a , ' b > (
4563 & ' a self ,
4664 buff : & ' b [ u8 ] ,
4765 ) -> impl Future < Output = Vec < u8 > > + Captures2 < ' a , ' b > {
48- //~^ ERROR return type captures more lifetimes than trait definition
4966 async move { buff. to_vec ( ) }
5067 }
5168
69+ // This error message is awkward, but `impl Future<Output = Vec<u8>>`
70+ // cannot outlive `'a` (from the trait signature) because it captures
71+ // both `T` and `'b`.
72+ #[ cfg( failure) ]
5273 fn async_fn_reduce_outlive < ' a , ' b , T > (
5374 & ' a self ,
5475 buff : & ' b [ u8 ] ,
5576 t : T ,
5677 ) -> impl Future < Output = Vec < u8 > > {
57- //~^ ERROR the parameter type `T` may not live long enough
78+ //[failure] ~^ ERROR lifetime mismatch
5879 async move {
5980 let _t = t;
6081 vec ! [ ]
6182 }
6283 }
6384
64- // OK: We remove the `Captures<'a>`, providing a guarantee that we don't capture `'a`,
65- // but we still fulfill the `Captures<'a>` trait bound.
85+ // Does not capture fewer lifetimes that trait def'n (not that it matters),
86+ // since impl also captures all in-scope lifetimes.
87+ #[ cfg( success) ]
6688 fn async_fn_reduce < ' a , ' b , T > ( & ' a self , buff : & ' b [ u8 ] , t : T ) -> impl Future < Output = Vec < u8 > > {
6789 async move {
6890 let _t = t;
0 commit comments