about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-01-26 17:00:34 +0000
committerMichael Goulet <michael@errs.io>2024-01-31 16:59:19 +0000
commitcd2fd34ca68f701ade233a980093ee4444f7da3a (patch)
tree5a05b9c584df6a0b6eb284f1d4a6807ead9bdc34
parent0eb2adb7e877ceaa7d4919f7b881508ee507ec3b (diff)
downloadrust-cd2fd34ca68f701ade233a980093ee4444f7da3a.tar.gz
rust-cd2fd34ca68f701ade233a980093ee4444f7da3a.zip
Add tests
-rw-r--r--tests/ui/async-await/async-fn/dyn-pos.rs14
-rw-r--r--tests/ui/async-await/async-fn/dyn-pos.stderr87
-rw-r--r--tests/ui/async-await/async-fn/edition-2015.rs8
-rw-r--r--tests/ui/async-await/async-fn/edition-2015.stderr22
-rw-r--r--tests/ui/async-await/async-fn/impl-header.rs8
-rw-r--r--tests/ui/async-await/async-fn/impl-header.stderr8
-rw-r--r--tests/ui/async-await/async-fn/impl-trait.rs15
-rw-r--r--tests/ui/async-await/async-fn/method-call-pos.rs7
-rw-r--r--tests/ui/async-await/async-fn/method-call-pos.stderr14
9 files changed, 183 insertions, 0 deletions
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 <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`.
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<T: async Fn()>() {}
+
+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
+