Skip to content

Commit 5bd423a

Browse files
committed
introduce more tests covering async fn surface
1 parent 076b0d0 commit 5bd423a

13 files changed

+239
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2018
2+
// run-pass
3+
4+
// Test that we can use async fns with multiple arbitrary lifetimes.
5+
6+
#![feature(async_await, await_macro)]
7+
8+
async fn multiple_elided_lifetimes(_: &u8, _: &u8) {}
9+
10+
fn main() {
11+
let _ = multiple_elided_lifetimes(&22, &44);
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
// run-pass
3+
4+
// Test that we can use async fns with multiple arbitrary lifetimes.
5+
6+
#![feature(arbitrary_self_types, async_await, await_macro)]
7+
8+
async fn multiple_named_lifetimes<'a, 'b>(_: &'a u8, _: &'b u8, _: fn(&u8)) {}
9+
10+
fn gimme(_: &u8) { }
11+
12+
fn main() {
13+
let _ = multiple_named_lifetimes(&22, &44, gimme);
14+
}

src/test/ui/async-await/async-fn-multiple-lifetimes.rs renamed to src/test/ui/async-await/multiple-lifetimes/hrtb.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
// Test that we can use async fns with multiple arbitrary lifetimes.
55

66
#![feature(arbitrary_self_types, async_await, await_macro)]
7+
#![allow(dead_code)]
78

89
use std::ops::Add;
910

10-
async fn multiple_named_lifetimes<'a, 'b>(_: &'a u8, _: &'b u8) {}
11-
1211
async fn multiple_hrtb_and_single_named_lifetime_ok<'c>(
1312
_: impl for<'a> Add<&'a u8>,
1413
_: impl for<'b> Add<&'b u8>,
1514
_: &'c u8,
1615
) {}
1716

18-
async fn multiple_elided_lifetimes(_: &u8, _: &u8) {}
19-
2017
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2018
2+
// run-pass
3+
4+
// Test that we can use async fns with multiple arbitrary lifetimes.
5+
6+
#![feature(arbitrary_self_types, async_await, await_macro)]
7+
8+
async fn multiple_named_lifetimes<'a, 'b>(_: &'a u8, _: &'b u8) {}
9+
10+
fn main() {
11+
let _ = multiple_named_lifetimes(&22, &44);
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// edition:2018
2+
// run-pass
3+
4+
#![feature(async_await)]
5+
6+
async fn lotsa_lifetimes<'a, 'b, 'c>(a: &'a u32, b: &'b u32, c: &'c u32) -> (&'a u32, &'b u32)
7+
where 'b: 'a
8+
{
9+
drop((a, c));
10+
(b, b)
11+
}
12+
13+
fn main() {
14+
let _ = lotsa_lifetimes(&22, &44, &66);
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// edition:2018
2+
// run-pass
3+
4+
// Test that a feature gate is needed to use `impl Trait` as the
5+
// return type of an async.
6+
7+
#![feature(async_await, member_constraints)]
8+
9+
trait Trait<'a, 'b> { }
10+
impl<T> Trait<'_, '_> for T { }
11+
12+
async fn async_ret_impl_trait<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a, 'b> {
13+
(a, b)
14+
}
15+
16+
fn main() {
17+
let _ = async_ret_impl_trait(&22, &44);
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
#![feature(arbitrary_self_types, async_await, await_macro)]
7+
8+
trait Trait<'a, 'b> { }
9+
impl<T> Trait<'_, '_> for T { }
10+
11+
async fn async_ret_impl_trait<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a, 'b> {
12+
//~^ ERROR ambiguous lifetime bound
13+
(a, b)
14+
}
15+
16+
fn main() {
17+
let _ = async_ret_impl_trait(&22, &44);
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: ambiguous lifetime bound in `impl Trait`
2+
--> $DIR/ret-impl-trait-no-fg.rs:11:64
3+
|
4+
LL | async fn async_ret_impl_trait<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a, 'b> {
5+
| ^^^^^^^^^^^^^^^^^^ neither `'a` nor `'b` outlives the other
6+
|
7+
= help: add #![feature(member_constraints)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#![feature(async_await, member_constraints)]
7+
8+
trait Trait<'a> { }
9+
impl<T> Trait<'_> for T { }
10+
11+
// Only `'a` permitted in return type, not `'b`.
12+
async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
13+
//~^ ERROR lifetime mismatch
14+
(a, b)
15+
}
16+
17+
// As above, but `'b: 'a`, so return type ca be inferred to `(&'a u8,
18+
// &'a u8)`.
19+
async fn async_ret_impl_trait2<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a>
20+
where
21+
'b: 'a,
22+
{
23+
(a, b)
24+
}
25+
26+
fn main() {
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0623]: lifetime mismatch
2+
--> $DIR/ret-impl-trait-one.rs:12:65
3+
|
4+
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
5+
| ------ ^^^^^^^^^^^^^^
6+
| | |
7+
| | ...but data from `b` is returned here
8+
| this parameter and the return type are declared with different lifetimes...
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)