Skip to content

Commit a694782

Browse files
committed
lifetime elision: add non-conforming-to-fn tests.
1 parent 43a2cbd commit a694782

27 files changed

+2195
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/lt-ref-self-async.rs:15:42
3+
|
4+
LL | async fn ref_self(&self, f: &u32) -> &u32 {
5+
| ^
6+
|
7+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
8+
9+
error[E0106]: missing lifetime specifier
10+
--> $DIR/lt-ref-self-async.rs:23:48
11+
|
12+
LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
13+
| ^
14+
|
15+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
16+
17+
error[E0106]: missing lifetime specifier
18+
--> $DIR/lt-ref-self-async.rs:29:57
19+
|
20+
LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
21+
| ^
22+
|
23+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
24+
25+
error[E0106]: missing lifetime specifier
26+
--> $DIR/lt-ref-self-async.rs:35:57
27+
|
28+
LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
29+
| ^
30+
|
31+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
32+
33+
error[E0106]: missing lifetime specifier
34+
--> $DIR/lt-ref-self-async.rs:41:66
35+
|
36+
LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
37+
| ^
38+
|
39+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
40+
41+
error[E0106]: missing lifetime specifier
42+
--> $DIR/lt-ref-self-async.rs:47:62
43+
|
44+
LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
45+
| ^
46+
|
47+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
48+
49+
error: aborting due to 6 previous errors
50+
51+
For more information about this error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// edition:2018
2+
3+
#![feature(async_await)]
4+
5+
#![feature(arbitrary_self_types)]
6+
#![allow(non_snake_case)]
7+
8+
use std::pin::Pin;
9+
10+
struct Struct<'a> { data: &'a u32 }
11+
12+
impl<'a> Struct<'a> {
13+
// Test using `&self` sugar:
14+
15+
async fn ref_self(&self, f: &u32) -> &u32 {
16+
//~^ ERROR cannot infer an appropriate lifetime
17+
//~| ERROR missing lifetime specifier
18+
f
19+
}
20+
21+
// Test using `&Self` explicitly:
22+
23+
async fn ref_Self(self: &Self, f: &u32) -> &u32 {
24+
//~^ ERROR cannot infer an appropriate lifetime
25+
//~| ERROR missing lifetime specifier
26+
f
27+
}
28+
29+
async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
30+
//~^ ERROR cannot infer an appropriate lifetime
31+
//~| ERROR missing lifetime specifier
32+
f
33+
}
34+
35+
async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
36+
//~^ ERROR cannot infer an appropriate lifetime
37+
//~| ERROR missing lifetime specifier
38+
f
39+
}
40+
41+
async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
42+
//~^ ERROR cannot infer an appropriate lifetime
43+
//~| ERROR missing lifetime specifier
44+
f
45+
}
46+
47+
async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
48+
//~^ ERROR cannot infer an appropriate lifetime
49+
//~| ERROR missing lifetime specifier
50+
f
51+
}
52+
}
53+
54+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/lt-ref-self-async.rs:15:42
3+
|
4+
LL | async fn ref_self(&self, f: &u32) -> &u32 {
5+
| ^
6+
|
7+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
8+
9+
error[E0106]: missing lifetime specifier
10+
--> $DIR/lt-ref-self-async.rs:23:48
11+
|
12+
LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
13+
| ^
14+
|
15+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
16+
17+
error[E0106]: missing lifetime specifier
18+
--> $DIR/lt-ref-self-async.rs:29:57
19+
|
20+
LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
21+
| ^
22+
|
23+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
24+
25+
error[E0106]: missing lifetime specifier
26+
--> $DIR/lt-ref-self-async.rs:35:57
27+
|
28+
LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
29+
| ^
30+
|
31+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
32+
33+
error[E0106]: missing lifetime specifier
34+
--> $DIR/lt-ref-self-async.rs:41:66
35+
|
36+
LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
37+
| ^
38+
|
39+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
40+
41+
error[E0106]: missing lifetime specifier
42+
--> $DIR/lt-ref-self-async.rs:47:62
43+
|
44+
LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
45+
| ^
46+
|
47+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
48+
49+
error: cannot infer an appropriate lifetime
50+
--> $DIR/lt-ref-self-async.rs:15:30
51+
|
52+
LL | async fn ref_self(&self, f: &u32) -> &u32 {
53+
| ^ ---- this return type evaluates to the `'static` lifetime...
54+
| |
55+
| ...but this borrow...
56+
|
57+
note: ...can't outlive the lifetime '_ as defined on the method body at 15:23
58+
--> $DIR/lt-ref-self-async.rs:15:23
59+
|
60+
LL | async fn ref_self(&self, f: &u32) -> &u32 {
61+
| ^
62+
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime '_ as defined on the method body at 15:23
63+
|
64+
LL | async fn ref_self(&self, f: &u32) -> &u32 + '_ {
65+
| ^^^^^^^^^
66+
67+
error: cannot infer an appropriate lifetime
68+
--> $DIR/lt-ref-self-async.rs:23:36
69+
|
70+
LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
71+
| ^ ---- this return type evaluates to the `'static` lifetime...
72+
| |
73+
| ...but this borrow...
74+
|
75+
note: ...can't outlive the lifetime '_ as defined on the method body at 23:29
76+
--> $DIR/lt-ref-self-async.rs:23:29
77+
|
78+
LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 {
79+
| ^
80+
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime '_ as defined on the method body at 23:29
81+
|
82+
LL | async fn ref_Self(self: &Self, f: &u32) -> &u32 + '_ {
83+
| ^^^^^^^^^
84+
85+
error: cannot infer an appropriate lifetime
86+
--> $DIR/lt-ref-self-async.rs:29:45
87+
|
88+
LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
89+
| ^ ---- this return type evaluates to the `'static` lifetime...
90+
| |
91+
| ...but this borrow...
92+
|
93+
note: ...can't outlive the lifetime '_ as defined on the method body at 29:37
94+
--> $DIR/lt-ref-self-async.rs:29:37
95+
|
96+
LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
97+
| ^
98+
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime '_ as defined on the method body at 29:37
99+
|
100+
LL | async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 + '_ {
101+
| ^^^^^^^^^
102+
103+
error: cannot infer an appropriate lifetime
104+
--> $DIR/lt-ref-self-async.rs:35:45
105+
|
106+
LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
107+
| ^ ---- this return type evaluates to the `'static` lifetime...
108+
| |
109+
| ...but this borrow...
110+
|
111+
note: ...can't outlive the lifetime '_ as defined on the method body at 35:37
112+
--> $DIR/lt-ref-self-async.rs:35:37
113+
|
114+
LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
115+
| ^
116+
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime '_ as defined on the method body at 35:37
117+
|
118+
LL | async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 + '_ {
119+
| ^^^^^^^^^
120+
121+
error: cannot infer an appropriate lifetime
122+
--> $DIR/lt-ref-self-async.rs:41:54
123+
|
124+
LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
125+
| ^ ---- this return type evaluates to the `'static` lifetime...
126+
| |
127+
| ...but this borrow...
128+
|
129+
note: ...can't outlive the lifetime '_ as defined on the method body at 41:45
130+
--> $DIR/lt-ref-self-async.rs:41:45
131+
|
132+
LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
133+
| ^
134+
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime '_ as defined on the method body at 41:45
135+
|
136+
LL | async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 + '_ {
137+
| ^^^^^^^^^
138+
139+
error: cannot infer an appropriate lifetime
140+
--> $DIR/lt-ref-self-async.rs:47:50
141+
|
142+
LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
143+
| ^ ---- this return type evaluates to the `'static` lifetime...
144+
| |
145+
| ...but this borrow...
146+
|
147+
note: ...can't outlive the lifetime '_ as defined on the method body at 47:41
148+
--> $DIR/lt-ref-self-async.rs:47:41
149+
|
150+
LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
151+
| ^
152+
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime '_ as defined on the method body at 47:41
153+
|
154+
LL | async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 + '_ {
155+
| ^^^^^^^^^
156+
157+
error: aborting due to 12 previous errors
158+
159+
For more information about this error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/multiple-ref-self-async.rs:24:74
3+
|
4+
LL | async fn wrap_ref_Self_ref_Self(self: Wrap<&Self, &Self>, f: &u8) -> &u8 {
5+
| ^
6+
|
7+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
8+
9+
error[E0106]: missing lifetime specifier
10+
--> $DIR/multiple-ref-self-async.rs:30:84
11+
|
12+
LL | async fn box_wrap_ref_Self_ref_Self(self: Box<Wrap<&Self, &Self>>, f: &u32) -> &u32 {
13+
| ^
14+
|
15+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
16+
17+
error[E0106]: missing lifetime specifier
18+
--> $DIR/multiple-ref-self-async.rs:36:84
19+
|
20+
LL | async fn pin_wrap_ref_Self_ref_Self(self: Pin<Wrap<&Self, &Self>>, f: &u32) -> &u32 {
21+
| ^
22+
|
23+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
24+
25+
error[E0106]: missing lifetime specifier
26+
--> $DIR/multiple-ref-self-async.rs:42:93
27+
|
28+
LL | async fn box_box_wrap_ref_Self_ref_Self(self: Box<Box<Wrap<&Self, &Self>>>, f: &u32) -> &u32 {
29+
| ^
30+
|
31+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
32+
33+
error[E0106]: missing lifetime specifier
34+
--> $DIR/multiple-ref-self-async.rs:48:93
35+
|
36+
LL | async fn box_pin_wrap_ref_Self_ref_Self(self: Box<Pin<Wrap<&Self, &Self>>>, f: &u32) -> &u32 {
37+
| ^
38+
|
39+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
40+
41+
error: aborting due to 5 previous errors
42+
43+
For more information about this error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// edition:2018
2+
3+
#![feature(async_await)]
4+
5+
#![feature(arbitrary_self_types)]
6+
#![allow(non_snake_case)]
7+
8+
use std::marker::PhantomData;
9+
use std::ops::Deref;
10+
use std::pin::Pin;
11+
12+
struct Struct { }
13+
14+
struct Wrap<T, P>(T, PhantomData<P>);
15+
16+
impl<T, P> Deref for Wrap<T, P> {
17+
type Target = T;
18+
fn deref(&self) -> &T { &self.0 }
19+
}
20+
21+
impl Struct {
22+
// Test using multiple `&Self`:
23+
24+
async fn wrap_ref_Self_ref_Self(self: Wrap<&Self, &Self>, f: &u8) -> &u8 {
25+
//~^ ERROR missing lifetime specifier
26+
//~| ERROR cannot infer an appropriate lifetime
27+
f
28+
}
29+
30+
async fn box_wrap_ref_Self_ref_Self(self: Box<Wrap<&Self, &Self>>, f: &u32) -> &u32 {
31+
//~^ ERROR missing lifetime specifier
32+
//~| ERROR cannot infer an appropriate lifetime
33+
f
34+
}
35+
36+
async fn pin_wrap_ref_Self_ref_Self(self: Pin<Wrap<&Self, &Self>>, f: &u32) -> &u32 {
37+
//~^ ERROR missing lifetime specifier
38+
//~| ERROR cannot infer an appropriate lifetime
39+
f
40+
}
41+
42+
async fn box_box_wrap_ref_Self_ref_Self(self: Box<Box<Wrap<&Self, &Self>>>, f: &u32) -> &u32 {
43+
//~^ ERROR missing lifetime specifier
44+
//~| ERROR cannot infer an appropriate lifetime
45+
f
46+
}
47+
48+
async fn box_pin_wrap_ref_Self_ref_Self(self: Box<Pin<Wrap<&Self, &Self>>>, f: &u32) -> &u32 {
49+
//~^ ERROR missing lifetime specifier
50+
//~| ERROR cannot infer an appropriate lifetime
51+
f
52+
}
53+
}
54+
55+
fn main() { }

0 commit comments

Comments
 (0)