1
1
// edition:2021
2
+ // revisions: success failure
3
+ //[success] check-pass
2
4
3
5
#![ feature( return_position_impl_trait_in_trait) ]
4
6
#![ allow( incomplete_features) ]
@@ -11,16 +13,25 @@ impl<T> Captures<'_> for T {}
11
13
trait Captures2 < ' a , ' b > { }
12
14
impl < T > Captures2 < ' _ , ' _ > for T { }
13
15
14
- pub trait AsyncTrait {
16
+ trait AsyncTrait {
17
+ #[ cfg( success) ]
15
18
fn async_fn ( & self , buff : & [ u8 ] ) -> impl Future < Output = Vec < u8 > > ;
19
+
20
+ #[ cfg( success) ]
16
21
fn async_fn_early < ' a : ' a > ( & self , buff : & ' a [ u8 ] ) -> impl Future < Output = Vec < u8 > > ;
22
+
23
+ #[ cfg( success) ]
17
24
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) ]
19
28
fn async_fn_reduce_outlive < ' a , T > (
20
29
& ' a self ,
21
30
buff : & [ u8 ] ,
22
31
t : T ,
23
32
) -> impl Future < Output = Vec < u8 > > + ' a ;
33
+
34
+ #[ cfg( success) ]
24
35
fn async_fn_reduce < ' a , T > (
25
36
& ' a self ,
26
37
buff : & [ u8 ] ,
@@ -31,38 +42,49 @@ pub trait AsyncTrait {
31
42
pub struct Struct ;
32
43
33
44
impl 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) ]
34
48
fn async_fn < ' a > ( & self , buff : & ' a [ u8 ] ) -> impl Future < Output = Vec < u8 > > + ' a {
35
- //~^ ERROR return type captures more lifetimes than trait definition
36
49
async move { buff. to_vec ( ) }
37
50
}
38
51
52
+ // Does not capture more lifetimes that trait def'n, since trait def'n
53
+ // implicitly captures all in-scope lifetimes.
54
+ #[ cfg( success) ]
39
55
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
41
56
async move { buff. to_vec ( ) }
42
57
}
43
58
59
+ // Does not capture more lifetimes that trait def'n, since trait def'n
60
+ // implicitly captures all in-scope lifetimes.
61
+ #[ cfg( success) ]
44
62
fn async_fn_multiple < ' a , ' b > (
45
63
& ' a self ,
46
64
buff : & ' b [ u8 ] ,
47
65
) -> impl Future < Output = Vec < u8 > > + Captures2 < ' a , ' b > {
48
- //~^ ERROR return type captures more lifetimes than trait definition
49
66
async move { buff. to_vec ( ) }
50
67
}
51
68
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) ]
52
73
fn async_fn_reduce_outlive < ' a , ' b , T > (
53
74
& ' a self ,
54
75
buff : & ' b [ u8 ] ,
55
76
t : T ,
56
77
) -> impl Future < Output = Vec < u8 > > {
57
- //~^ ERROR the parameter type `T` may not live long enough
78
+ //[failure] ~^ ERROR lifetime mismatch
58
79
async move {
59
80
let _t = t;
60
81
vec ! [ ]
61
82
}
62
83
}
63
84
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) ]
66
88
fn async_fn_reduce < ' a , ' b , T > ( & ' a self , buff : & ' b [ u8 ] , t : T ) -> impl Future < Output = Vec < u8 > > {
67
89
async move {
68
90
let _t = t;
0 commit comments