Skip to content

Commit 5ce8f7a

Browse files
committed
Add async versions of arbitrary_self_types_pin_lifetime tests.
1 parent f395787 commit 5ce8f7a

7 files changed

+230
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// check-pass
2+
// edition:2018
3+
4+
#![feature(async_await)]
5+
6+
use std::pin::Pin;
7+
use std::task::{Context, Poll};
8+
9+
struct Foo;
10+
11+
impl Foo {
12+
async fn pin_ref(self: Pin<&Self>) -> Pin<&Self> { self }
13+
14+
async fn pin_mut(self: Pin<&mut Self>) -> Pin<&mut Self> { self }
15+
16+
async fn pin_pin_pin_ref(self: Pin<Pin<Pin<&Self>>>) -> Pin<Pin<Pin<&Self>>> { self }
17+
18+
async fn pin_ref_impl_trait(self: Pin<&Self>) -> impl Clone + '_ { self }
19+
20+
fn b(self: Pin<&Foo>, f: &Foo) -> Pin<&Foo> { self }
21+
}
22+
23+
type Alias<T> = Pin<T>;
24+
impl Foo {
25+
async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> Alias<&Self> { self }
26+
}
27+
28+
// FIXME(Centril): extend with the rest of the non-`async fn` test
29+
// when we allow `async fn`s inside traits and trait implementations.
30+
31+
fn main() {
32+
let mut foo = Foo;
33+
{ Pin::new(&foo).pin_ref() };
34+
{ Pin::new(&mut foo).pin_mut() };
35+
{ Pin::new(Pin::new(Pin::new(&foo))).pin_pin_pin_ref() };
36+
{ Pin::new(&foo).pin_ref_impl_trait() };
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:10:48
3+
|
4+
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
5+
| - ^^^^^^^^ returning this value requires that `'_` must outlive `'static`
6+
| |
7+
| lifetime `'_` defined here
8+
help: to allow this `impl Trait` to capture borrowed data with lifetime `'_`, add `'_` as a constraint
9+
|
10+
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
11+
| ^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// edition:2018
2+
3+
#![feature(async_await)]
4+
5+
use std::pin::Pin;
6+
7+
struct Foo;
8+
9+
impl Foo {
10+
async fn f(self: Pin<&Self>) -> impl Clone { self }
11+
//~^ ERROR cannot infer an appropriate lifetime
12+
}
13+
14+
fn main() {
15+
{ Pin::new(&Foo).f() };
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: cannot infer an appropriate lifetime
2+
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:10:16
3+
|
4+
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
5+
| ^^^^ ---------- this return type evaluates to the `'static` lifetime...
6+
| |
7+
| ...but this borrow...
8+
|
9+
note: ...can't outlive the lifetime '_ as defined on the method body at 10:26
10+
--> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:10:26
11+
|
12+
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
13+
| ^
14+
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 10:26
15+
|
16+
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
17+
| ^^^^^^^^^^^^^^^
18+
19+
error: aborting due to previous error
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:45
3+
|
4+
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
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/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:60
11+
|
12+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
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/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:67
19+
|
20+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
21+
| ^
22+
|
23+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
24+
25+
error: aborting due to 3 previous errors
26+
27+
For more information about this error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// edition:2018
2+
3+
#![feature(async_await)]
4+
5+
use std::pin::Pin;
6+
7+
struct Foo;
8+
9+
impl Foo {
10+
async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
11+
//~^ ERROR missing lifetime specifier
12+
//~| ERROR cannot infer an appropriate lifetime
13+
// FIXME: should be E0623?
14+
15+
async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
16+
//~^ ERROR missing lifetime specifier
17+
//~| ERROR cannot infer an appropriate lifetime
18+
//~| ERROR missing lifetime specifier
19+
//~| ERROR cannot infer an appropriate lifetime
20+
// FIXME: should be E0623?
21+
}
22+
23+
type Alias<T> = Pin<T>;
24+
impl Foo {
25+
async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } //~ ERROR E0623
26+
}
27+
28+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:45
3+
|
4+
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
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/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:60
11+
|
12+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
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/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:67
19+
|
20+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
21+
| ^
22+
|
23+
= note: return-position elided lifetimes require exactly one input-position elided lifetime, found multiple.
24+
25+
error: cannot infer an appropriate lifetime
26+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:33
27+
|
28+
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
29+
| ^ ---- this return type evaluates to the `'static` lifetime...
30+
| |
31+
| ...but this borrow...
32+
|
33+
note: ...can't outlive the lifetime '_ as defined on the method body at 10:26
34+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:10:26
35+
|
36+
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo { f }
37+
| ^
38+
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 10:26
39+
|
40+
LL | async fn a(self: Pin<&Foo>, f: &Foo) -> &Foo + '_ { f }
41+
| ^^^^^^^^^
42+
43+
error: cannot infer an appropriate lifetime
44+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:16
45+
|
46+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
47+
| ^^^^ ...but this borrow... ----------------- this return type evaluates to the `'static` lifetime...
48+
|
49+
note: ...can't outlive the lifetime '_ as defined on the method body at 15:26
50+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:26
51+
|
52+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
53+
| ^
54+
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:26
55+
|
56+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) + '_ { (self, f) }
57+
| ^^^^^^^^^^^^^^^^^^^^^^
58+
59+
error: cannot infer an appropriate lifetime
60+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:34
61+
|
62+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
63+
| ^ ----------------- this return type evaluates to the `'static` lifetime...
64+
| |
65+
| ...but this borrow...
66+
|
67+
note: ...can't outlive the lifetime '_ as defined on the method body at 15:26
68+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:15:26
69+
|
70+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) { (self, f) }
71+
| ^
72+
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:26
73+
|
74+
LL | async fn c(self: Pin<&Self>, f: &Foo, g: &Foo) -> (Pin<&Foo>, &Foo) + '_ { (self, f) }
75+
| ^^^^^^^^^^^^^^^^^^^^^^
76+
77+
error[E0623]: lifetime mismatch
78+
--> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:25:58
79+
|
80+
LL | async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg }
81+
| ----- ^^^
82+
| | |
83+
| | ...but data from `arg` is returned here
84+
| this parameter and the return type are declared with different lifetimes...
85+
86+
error: aborting due to 7 previous errors
87+
88+
For more information about this error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)