Add tests

This commit is contained in:
Michael Goulet 2024-01-26 17:00:34 +00:00
parent 0eb2adb7e8
commit cd2fd34ca6
9 changed files with 183 additions and 0 deletions

View File

@ -0,0 +1,14 @@
// edition:2018
#![feature(async_closure)]
fn foo(x: &dyn async Fn()) {}
//~^ ERROR the trait `AsyncFn` cannot be made into an object
//~| ERROR the trait `AsyncFn` cannot be made into an object
//~| ERROR the trait `AsyncFn` cannot be made into an object
//~| ERROR the trait `AsyncFn` cannot be made into an object
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
fn main() {}

View File

@ -0,0 +1,87 @@
error[E0038]: the trait `AsyncFn` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFn` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
error[E0038]: the trait `AsyncFn` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFn` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0038]: the trait `AsyncFn` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFn` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
--> $DIR/dyn-pos.rs:5:16
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0038]: the trait `AsyncFn` cannot be made into an object
--> $DIR/dyn-pos.rs:5:12
|
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^^^^^ `AsyncFn` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
::: $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0038`.

View File

@ -0,0 +1,8 @@
// FIXME(async_closures): This error message could be made better.
fn foo(x: impl async Fn()) -> impl async Fn() {}
//~^ ERROR expected
//~| ERROR expected
//~| ERROR expected
fn main() {}

View File

@ -0,0 +1,22 @@
error: expected one of `:` or `|`, found `)`
--> $DIR/edition-2015.rs:3:26
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
| ^ expected one of `:` or `|`
error: expected one of `(`, `)`, `+`, `,`, `::`, or `<`, found `Fn`
--> $DIR/edition-2015.rs:3:22
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
| -^^ expected one of `(`, `)`, `+`, `,`, `::`, or `<`
| |
| help: missing `,`
error: expected one of `(`, `+`, `::`, `<`, `where`, or `{`, found `Fn`
--> $DIR/edition-2015.rs:3:42
|
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
| ^^ expected one of `(`, `+`, `::`, `<`, `where`, or `{`
error: aborting due to 3 previous errors

View File

@ -0,0 +1,8 @@
// edition:2018
struct F;
impl async Fn<()> for F {}
//~^ ERROR expected type, found keyword `async`
fn main() {}

View File

@ -0,0 +1,8 @@
error: expected type, found keyword `async`
--> $DIR/impl-header.rs:5:6
|
LL | impl async Fn<()> for F {}
| ^^^^^ expected type
error: aborting due to 1 previous error

View File

@ -0,0 +1,15 @@
// edition:2018
// check-pass
#![feature(async_closure, type_alias_impl_trait)]
type Tait = impl async Fn();
fn tait() -> Tait {
|| async {}
}
fn foo(x: impl async Fn()) -> impl async Fn() { x }
fn param<T: async Fn()>() {}
fn main() {}

View File

@ -0,0 +1,7 @@
// edition:2018
fn main() {
<_ as async Fn()>(|| async {});
//~^ ERROR expected identifier, found keyword `async`
//~| ERROR expected one of
}

View File

@ -0,0 +1,14 @@
error: expected identifier, found keyword `async`
--> $DIR/method-call-pos.rs:4:11
|
LL | <_ as async Fn()>(|| async {});
| ^^^^^ expected identifier, found keyword
error: expected one of `(`, `::`, `<`, or `>`, found `Fn`
--> $DIR/method-call-pos.rs:4:17
|
LL | <_ as async Fn()>(|| async {});
| ^^ expected one of `(`, `::`, `<`, or `>`
error: aborting due to 2 previous errors