Add tests for static async functions in traits

This patch adds test cases for AFIT, the majority of which are currently
expected to run as `check-fail`.
This commit is contained in:
Bryan Garza 2022-10-04 01:27:11 +00:00
parent 0da281b606
commit 97423d331f
19 changed files with 530 additions and 0 deletions

View File

@ -0,0 +1,24 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
use std::fmt::Debug;
trait MyTrait<'a, 'b, T> where Self: 'a, T: Debug + Sized + 'b {
type MyAssoc;// = (&'a T, &'b U);
async fn foo(&'a self, key: &'b T) -> Self::MyAssoc;
}
impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
type MyAssoc = (&'a U, &'b T);
async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
(self, key)
}
}
//~^^^^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
//~| ERROR cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements
fn main() {}

View File

@ -0,0 +1,57 @@
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
--> $DIR/async-associated-types.rs:14:6
|
LL | impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
| ^^
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `(&'a U, &'b T)`
found `(&U, &T)`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `MyTrait<'static, 'static, T>`
found `MyTrait<'_, '_, T>`
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime `'b` as defined here...
--> $DIR/async-associated-types.rs:14:10
|
LL | impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
| ^^
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `(&'a U, &'b T)`
found `(&U, &T)`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the types are compatible
--> $DIR/async-associated-types.rs:17:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
| ^^^^^^^^^^^^^^
= note: expected `MyTrait<'static, 'static, T>`
found `MyTrait<'_, '_, T>`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0495`.

View File

@ -0,0 +1,31 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
use std::future::Future;
trait MyTrait {
type Fut<'a>: Future<Output = i32>
where
Self: 'a;
async fn foo(&self) -> Self::Fut<'a>;
//~^ ERROR use of undeclared lifetime name `'a`
//~| ERROR the parameter type `Self` may not live long enough
}
impl MyTrait for i32 {
type Fut<'a> = impl Future + 'a
where
Self: 'a;
//~^^^ ERROR `impl Trait` in type aliases is unstable
fn foo<'a>(&'a self) -> Self::Fut<'a> {
async {
*self
}
}
}
fn main() {}

View File

@ -0,0 +1,42 @@
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/async-associated-types2-desugared.rs:13:38
|
LL | async fn foo(&self) -> Self::Fut<'a>;
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | async fn foo<'a>(&self) -> Self::Fut<'a>;
| ++++
help: consider introducing lifetime `'a` here
|
LL | trait MyTrait<'a> {
| ++++
error[E0658]: `impl Trait` in type aliases is unstable
--> $DIR/async-associated-types2-desugared.rs:19:20
|
LL | type Fut<'a> = impl Future + 'a
| ^^^^^^^^^^^^^^^^
|
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
error[E0310]: the parameter type `Self` may not live long enough
--> $DIR/async-associated-types2-desugared.rs:13:28
|
LL | async fn foo(&self) -> Self::Fut<'a>;
| ^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `Self: 'static`...
= note: ...so that the type `Self` will meet its required lifetime bounds...
note: ...that is required by this bound
--> $DIR/async-associated-types2-desugared.rs:11:15
|
LL | Self: 'a;
| ^^
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0261, E0310, E0658.
For more information about an error, try `rustc --explain E0261`.

View File

@ -0,0 +1,32 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
use std::future::Future;
trait MyTrait {
type Fut<'a>: Future<Output = i32>
where
Self: 'a;
fn foo(&self) -> Self::Fut<'a>;
//~^ ERROR use of undeclared lifetime name `'a`
}
impl MyTrait for i32 {
type Fut<'a> = impl Future + 'a
where
Self: 'a;
//~^^^ ERROR `impl Trait` in type aliases is unstable
//~| ERROR expected `<i32 as MyTrait>::Fut<'a>` to be a future that resolves to `i32`, but it resolves to `<<i32 as MyTrait>::Fut<'a> as Future>::Output`
fn foo<'a>(&'a self) -> Self::Fut<'a> {
//~^ ERROR `impl` item signature doesn't match `trait` item signature
async {
*self
}
}
}
fn main() {}

View File

@ -0,0 +1,63 @@
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/async-associated-types2.rs:13:32
|
LL | fn foo(&self) -> Self::Fut<'a>;
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn foo<'a>(&self) -> Self::Fut<'a>;
| ++++
help: consider introducing lifetime `'a` here
|
LL | trait MyTrait<'a> {
| ++++
error[E0658]: `impl Trait` in type aliases is unstable
--> $DIR/async-associated-types2.rs:18:20
|
LL | type Fut<'a> = impl Future + 'a
| ^^^^^^^^^^^^^^^^
|
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
error[E0271]: expected `<i32 as MyTrait>::Fut<'a>` to be a future that resolves to `i32`, but it resolves to `<<i32 as MyTrait>::Fut<'a> as Future>::Output`
--> $DIR/async-associated-types2.rs:18:20
|
LL | type Fut<'a> = impl Future + 'a
| ^^^^^^^^^^^^^^^^ expected `i32`, found associated type
|
= note: expected type `i32`
found associated type `<<i32 as MyTrait>::Fut<'a> as Future>::Output`
note: required by a bound in `MyTrait::Fut`
--> $DIR/async-associated-types2.rs:9:26
|
LL | type Fut<'a>: Future<Output = i32>
| ^^^^^^^^^^^^ required by this bound in `MyTrait::Fut`
help: consider constraining the associated type `<<i32 as MyTrait>::Fut<'a> as Future>::Output` to `i32`
|
LL | type Fut<'a> = impl Future<Output = i32> + 'a
| ++++++++++++++
error: `impl` item signature doesn't match `trait` item signature
--> $DIR/async-associated-types2.rs:24:5
|
LL | fn foo(&self) -> Self::Fut<'a>;
| ------------------------------- expected `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'static>`
...
LL | fn foo<'a>(&'a self) -> Self::Fut<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'1>`
|
= note: expected `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'static>`
found `fn(&'1 i32) -> <i32 as MyTrait>::Fut<'1>`
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
--> $DIR/async-associated-types2.rs:13:22
|
LL | fn foo(&self) -> Self::Fut<'a>;
| ^^^^ consider borrowing this type parameter in the trait
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0261, E0271, E0658.
For more information about an error, try `rustc --explain E0261`.

View File

@ -0,0 +1,17 @@
// check-pass
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
trait MyTrait {
async fn foo(&self) -> i32;
}
impl MyTrait for i32 {
async fn foo(&self) -> i32 {
*self
}
}
fn main() {}

View File

@ -0,0 +1,21 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
use std::fmt::Debug;
use std::hash::Hash;
trait MyTrait<T, U> {
async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
}
//~^^ ERROR the parameter type `U` may not live long enough
//~| ERROR the parameter type `T` may not live long enough
impl<T, U> MyTrait<T, U> for (T, U) {
async fn foo(&self) -> &(T, U) {
self
}
}
fn main() {}

View File

@ -0,0 +1,37 @@
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
|
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics-and-bounds.rs:10:18
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics-and-bounds.rs:10:18
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics-and-bounds.rs:10:28
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0311`.

View File

@ -0,0 +1,18 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
trait MyTrait<T, U> {
async fn foo(&self) -> &(T, U);
}
//~^^ ERROR the parameter type `U` may not live long enough
//~| ERROR the parameter type `T` may not live long enough
impl<T, U> MyTrait<T, U> for (T, U) {
async fn foo(&self) -> &(T, U) {
self
}
}
fn main() {}

View File

@ -0,0 +1,37 @@
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
|
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics.rs:7:18
|
LL | async fn foo(&self) -> &(T, U);
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
|
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
--> $DIR/async-generics.rs:7:18
|
LL | async fn foo(&self) -> &(T, U);
| ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
--> $DIR/async-generics.rs:7:28
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0311`.

View File

@ -0,0 +1,20 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
use std::fmt::Debug;
trait MyTrait<'a, 'b, T> {
async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
}
//~^^ ERROR the parameter type `Self` may not live long enough
//~| ERROR the parameter type `T` may not live long enough
impl<'a, 'b, T, U> MyTrait<'a, 'b, T> for U {
async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
(self, key)
}
}
fn main() {}

View File

@ -0,0 +1,23 @@
error[E0309]: the parameter type `Self` may not live long enough
--> $DIR/async-lifetimes-and-bounds.rs:9:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
| ^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `Self: 'a`...
= note: ...so that the reference type `&'a Self` does not outlive the data it points at
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/async-lifetimes-and-bounds.rs:9:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
| ^^^^^^^^^^^^^^^^^ ...so that the reference type `&'b T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound...
|
LL | trait MyTrait<'a, 'b, T: 'b> {
| ++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0309`.

View File

@ -0,0 +1,18 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
trait MyTrait<'a, 'b, T> {
async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T);
}
//~^^ ERROR the parameter type `Self` may not live long enough
//~| ERROR the parameter type `T` may not live long enough
impl<'a, 'b, T, U> MyTrait<'a, 'b, T> for U {
async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
(self, key)
}
}
fn main() {}

View File

@ -0,0 +1,23 @@
error[E0309]: the parameter type `Self` may not live long enough
--> $DIR/async-lifetimes.rs:7:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T);
| ^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `Self: 'a`...
= note: ...so that the reference type `&'a Self` does not outlive the data it points at
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/async-lifetimes.rs:7:43
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T);
| ^^^^^^^^^^^^^^^^^ ...so that the reference type `&'b T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound...
|
LL | trait MyTrait<'a, 'b, T: 'b> {
| ++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0309`.

View File

@ -0,0 +1,17 @@
// edition: 2021
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
trait MyTrait {
async fn foo(&self) -> i32;
}
impl MyTrait for i32 {
fn foo(&self) -> i32 {
//~^ ERROR: `i32` is not a future [E0277]
*self
}
}
fn main() {}

View File

@ -0,0 +1,17 @@
error[E0277]: `i32` is not a future
--> $DIR/fn-not-async-err.rs:11:22
|
LL | fn foo(&self) -> i32 {
| ^^^ `i32` is not a future
|
= help: the trait `Future` is not implemented for `i32`
= note: i32 must be a future or must implement `IntoFuture` to be awaited
note: required by a bound in `MyTrait::foo::{opaque#0}`
--> $DIR/fn-not-async-err.rs:7:28
|
LL | async fn foo(&self) -> i32;
| ^^^ required by this bound in `MyTrait::foo::{opaque#0}`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,21 @@
// edition: 2021
#![feature(async_fn_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> {
//~^ ERROR `impl Trait` only allowed in function and inherent method return types, not in `impl` method return [E0562]
async {
*self
}
}
}
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `impl` method return
--> $DIR/fn-not-async-err2.rs:13:22
|
LL | fn foo(&self) -> impl Future<Output = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0562`.