Add additional tests for static AFIT
This commit is contained in:
parent
11b1439380
commit
9a05081d5f
9 changed files with 169 additions and 0 deletions
|
@ -0,0 +1,21 @@
|
|||
// edition: 2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![feature(return_position_impl_trait_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
trait MyTrait {
|
||||
fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>>;
|
||||
}
|
||||
|
||||
impl MyTrait for i32 {
|
||||
async fn foo(&self) -> i32 {
|
||||
//~^ ERROR method `foo` has an incompatible type for trait
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,17 @@
|
|||
error[E0053]: method `foo` has an incompatible type for trait
|
||||
--> $DIR/async-example-desugared-boxed-in-trait.rs:15:28
|
||||
|
|
||||
LL | async fn foo(&self) -> i32 {
|
||||
| ^^^ expected struct `Pin`, found opaque type
|
||||
|
|
||||
note: type in trait
|
||||
--> $DIR/async-example-desugared-boxed-in-trait.rs:11:22
|
||||
|
|
||||
LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: expected fn pointer `fn(&i32) -> Pin<Box<dyn Future<Output = i32>>>`
|
||||
found fn pointer `fn(&i32) -> impl Future<Output = i32>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0053`.
|
|
@ -0,0 +1,23 @@
|
|||
// check-pass
|
||||
// edition: 2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![feature(return_position_impl_trait_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
trait MyTrait {
|
||||
async fn foo(&self) -> i32;
|
||||
}
|
||||
|
||||
impl MyTrait for i32 {
|
||||
fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
|
||||
Box::pin(async {
|
||||
*self
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,20 @@
|
|||
// check-pass
|
||||
// edition: 2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![feature(return_position_impl_trait_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
trait MyTrait {
|
||||
fn foo(&self) -> impl Future<Output = i32> + '_;
|
||||
}
|
||||
|
||||
impl MyTrait for i32 {
|
||||
async fn foo(&self) -> i32 {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
22
src/test/ui/async-await/in-trait/async-example-desugared.rs
Normal file
22
src/test/ui/async-await/in-trait/async-example-desugared.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
// check-pass
|
||||
// edition: 2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![feature(return_position_impl_trait_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
trait MyTrait {
|
||||
async fn foo(&self) -> i32;
|
||||
}
|
||||
|
||||
impl MyTrait for i32 {
|
||||
fn foo(&self) -> impl Future<Output = i32> + '_ {
|
||||
async {
|
||||
*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
21
src/test/ui/async-await/in-trait/async-recursive-generic.rs
Normal file
21
src/test/ui/async-await/in-trait/async-recursive-generic.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
// edition: 2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait MyTrait<T> {
|
||||
async fn foo_recursive(&self, n: usize) -> T;
|
||||
}
|
||||
|
||||
impl<T> MyTrait<T> for T where T: Copy {
|
||||
async fn foo_recursive(&self, n: usize) -> T {
|
||||
//~^ ERROR recursion in an `async fn` requires boxing
|
||||
if n > 0 {
|
||||
self.foo_recursive(n - 1).await
|
||||
} else {
|
||||
*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,12 @@
|
|||
error[E0733]: recursion in an `async fn` requires boxing
|
||||
--> $DIR/async-recursive-generic.rs:11:48
|
||||
|
|
||||
LL | async fn foo_recursive(&self, n: usize) -> T {
|
||||
| ^ recursive `async fn`
|
||||
|
|
||||
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
|
||||
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0733`.
|
21
src/test/ui/async-await/in-trait/async-recursive.rs
Normal file
21
src/test/ui/async-await/in-trait/async-recursive.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
// edition: 2021
|
||||
|
||||
#![feature(async_fn_in_trait)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait MyTrait {
|
||||
async fn foo_recursive(&self, n: usize) -> i32;
|
||||
}
|
||||
|
||||
impl MyTrait for i32 {
|
||||
async fn foo_recursive(&self, n: usize) -> i32 {
|
||||
//~^ ERROR recursion in an `async fn` requires boxing
|
||||
if n > 0 {
|
||||
self.foo_recursive(n - 1).await
|
||||
} else {
|
||||
*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
12
src/test/ui/async-await/in-trait/async-recursive.stderr
Normal file
12
src/test/ui/async-await/in-trait/async-recursive.stderr
Normal file
|
@ -0,0 +1,12 @@
|
|||
error[E0733]: recursion in an `async fn` requires boxing
|
||||
--> $DIR/async-recursive.rs:11:48
|
||||
|
|
||||
LL | async fn foo_recursive(&self, n: usize) -> i32 {
|
||||
| ^^^ recursive `async fn`
|
||||
|
|
||||
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
|
||||
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0733`.
|
Loading…
Add table
Add a link
Reference in a new issue