Skip to content

Commit 9a05081

Browse files
committed
Add additional tests for static AFIT
1 parent 11b1439 commit 9a05081

9 files changed

+169
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// edition: 2021
2+
3+
#![feature(async_fn_in_trait)]
4+
#![feature(return_position_impl_trait_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
use std::future::Future;
8+
use std::pin::Pin;
9+
10+
trait MyTrait {
11+
fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>>;
12+
}
13+
14+
impl MyTrait for i32 {
15+
async fn foo(&self) -> i32 {
16+
//~^ ERROR method `foo` has an incompatible type for trait
17+
*self
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0053]: method `foo` has an incompatible type for trait
2+
--> $DIR/async-example-desugared-boxed-in-trait.rs:15:28
3+
|
4+
LL | async fn foo(&self) -> i32 {
5+
| ^^^ expected struct `Pin`, found opaque type
6+
|
7+
note: type in trait
8+
--> $DIR/async-example-desugared-boxed-in-trait.rs:11:22
9+
|
10+
LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>>;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: expected fn pointer `fn(&i32) -> Pin<Box<dyn Future<Output = i32>>>`
13+
found fn pointer `fn(&i32) -> impl Future<Output = i32>`
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0053`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
// edition: 2021
3+
4+
#![feature(async_fn_in_trait)]
5+
#![feature(return_position_impl_trait_in_trait)]
6+
#![allow(incomplete_features)]
7+
8+
use std::future::Future;
9+
use std::pin::Pin;
10+
11+
trait MyTrait {
12+
async fn foo(&self) -> i32;
13+
}
14+
15+
impl MyTrait for i32 {
16+
fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
17+
Box::pin(async {
18+
*self
19+
})
20+
}
21+
}
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
// edition: 2021
3+
4+
#![feature(async_fn_in_trait)]
5+
#![feature(return_position_impl_trait_in_trait)]
6+
#![allow(incomplete_features)]
7+
8+
use std::future::Future;
9+
10+
trait MyTrait {
11+
fn foo(&self) -> impl Future<Output = i32> + '_;
12+
}
13+
14+
impl MyTrait for i32 {
15+
async fn foo(&self) -> i32 {
16+
*self
17+
}
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-pass
2+
// edition: 2021
3+
4+
#![feature(async_fn_in_trait)]
5+
#![feature(return_position_impl_trait_in_trait)]
6+
#![allow(incomplete_features)]
7+
8+
use std::future::Future;
9+
10+
trait MyTrait {
11+
async fn foo(&self) -> i32;
12+
}
13+
14+
impl MyTrait for i32 {
15+
fn foo(&self) -> impl Future<Output = i32> + '_ {
16+
async {
17+
*self
18+
}
19+
}
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// edition: 2021
2+
3+
#![feature(async_fn_in_trait)]
4+
#![allow(incomplete_features)]
5+
6+
trait MyTrait<T> {
7+
async fn foo_recursive(&self, n: usize) -> T;
8+
}
9+
10+
impl<T> MyTrait<T> for T where T: Copy {
11+
async fn foo_recursive(&self, n: usize) -> T {
12+
//~^ ERROR recursion in an `async fn` requires boxing
13+
if n > 0 {
14+
self.foo_recursive(n - 1).await
15+
} else {
16+
*self
17+
}
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0733]: recursion in an `async fn` requires boxing
2+
--> $DIR/async-recursive-generic.rs:11:48
3+
|
4+
LL | async fn foo_recursive(&self, n: usize) -> T {
5+
| ^ recursive `async fn`
6+
|
7+
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
8+
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0733`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// edition: 2021
2+
3+
#![feature(async_fn_in_trait)]
4+
#![allow(incomplete_features)]
5+
6+
trait MyTrait {
7+
async fn foo_recursive(&self, n: usize) -> i32;
8+
}
9+
10+
impl MyTrait for i32 {
11+
async fn foo_recursive(&self, n: usize) -> i32 {
12+
//~^ ERROR recursion in an `async fn` requires boxing
13+
if n > 0 {
14+
self.foo_recursive(n - 1).await
15+
} else {
16+
*self
17+
}
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0733]: recursion in an `async fn` requires boxing
2+
--> $DIR/async-recursive.rs:11:48
3+
|
4+
LL | async fn foo_recursive(&self, n: usize) -> i32 {
5+
| ^^^ recursive `async fn`
6+
|
7+
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
8+
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0733`.

0 commit comments

Comments
 (0)