diff --git a/tests/ui/async-await/async-fn/dyn-pos.rs b/tests/ui/async-await/async-fn/dyn-pos.rs new file mode 100644 index 00000000000..3201fb8dbf3 --- /dev/null +++ b/tests/ui/async-await/async-fn/dyn-pos.rs @@ -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() {} diff --git a/tests/ui/async-await/async-fn/dyn-pos.stderr b/tests/ui/async-await/async-fn/dyn-pos.stderr new file mode 100644 index 00000000000..c9323526516 --- /dev/null +++ b/tests/ui/async-await/async-fn/dyn-pos.stderr @@ -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 + --> $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 + --> $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 + --> $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 + --> $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 + --> $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 + --> $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 + --> $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`. diff --git a/tests/ui/async-await/async-fn/edition-2015.rs b/tests/ui/async-await/async-fn/edition-2015.rs new file mode 100644 index 00000000000..287d05ecacb --- /dev/null +++ b/tests/ui/async-await/async-fn/edition-2015.rs @@ -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() {} diff --git a/tests/ui/async-await/async-fn/edition-2015.stderr b/tests/ui/async-await/async-fn/edition-2015.stderr new file mode 100644 index 00000000000..e79b92ccf9f --- /dev/null +++ b/tests/ui/async-await/async-fn/edition-2015.stderr @@ -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 + diff --git a/tests/ui/async-await/async-fn/impl-header.rs b/tests/ui/async-await/async-fn/impl-header.rs new file mode 100644 index 00000000000..fb1844384ae --- /dev/null +++ b/tests/ui/async-await/async-fn/impl-header.rs @@ -0,0 +1,8 @@ +// edition:2018 + +struct F; + +impl async Fn<()> for F {} +//~^ ERROR expected type, found keyword `async` + +fn main() {} diff --git a/tests/ui/async-await/async-fn/impl-header.stderr b/tests/ui/async-await/async-fn/impl-header.stderr new file mode 100644 index 00000000000..02cb4326242 --- /dev/null +++ b/tests/ui/async-await/async-fn/impl-header.stderr @@ -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 + diff --git a/tests/ui/async-await/async-fn/impl-trait.rs b/tests/ui/async-await/async-fn/impl-trait.rs new file mode 100644 index 00000000000..97f6696fe14 --- /dev/null +++ b/tests/ui/async-await/async-fn/impl-trait.rs @@ -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() {} + +fn main() {} diff --git a/tests/ui/async-await/async-fn/method-call-pos.rs b/tests/ui/async-await/async-fn/method-call-pos.rs new file mode 100644 index 00000000000..aaa0245b986 --- /dev/null +++ b/tests/ui/async-await/async-fn/method-call-pos.rs @@ -0,0 +1,7 @@ +// edition:2018 + +fn main() { + <_ as async Fn()>(|| async {}); + //~^ ERROR expected identifier, found keyword `async` + //~| ERROR expected one of +} diff --git a/tests/ui/async-await/async-fn/method-call-pos.stderr b/tests/ui/async-await/async-fn/method-call-pos.stderr new file mode 100644 index 00000000000..527515a1b44 --- /dev/null +++ b/tests/ui/async-await/async-fn/method-call-pos.stderr @@ -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 +