Skip to content

Commit 283810f

Browse files
Add tests
1 parent 725b9ed commit 283810f

9 files changed

+183
-0
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
3+
#![feature(async_closure)]
4+
5+
fn foo(x: &dyn async Fn()) {}
6+
//~^ ERROR the trait `AsyncFn` cannot be made into an object
7+
//~| ERROR the trait `AsyncFn` cannot be made into an object
8+
//~| ERROR the trait `AsyncFn` cannot be made into an object
9+
//~| ERROR the trait `AsyncFn` cannot be made into an object
10+
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
11+
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
12+
//~| ERROR the trait `AsyncFnMut` cannot be made into an object
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
error[E0038]: the trait `AsyncFn` cannot be made into an object
2+
--> $DIR/dyn-pos.rs:5:16
3+
|
4+
LL | fn foo(x: &dyn async Fn()) {}
5+
| ^^^^^^^^^^ `AsyncFn` cannot be made into an object
6+
|
7+
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>
8+
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
9+
|
10+
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
11+
12+
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
13+
--> $DIR/dyn-pos.rs:5:16
14+
|
15+
LL | fn foo(x: &dyn async Fn()) {}
16+
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
17+
|
18+
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>
19+
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
20+
|
21+
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
22+
23+
error[E0038]: the trait `AsyncFn` cannot be made into an object
24+
--> $DIR/dyn-pos.rs:5:16
25+
|
26+
LL | fn foo(x: &dyn async Fn()) {}
27+
| ^^^^^^^^^^ `AsyncFn` cannot be made into an object
28+
|
29+
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>
30+
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
31+
|
32+
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
33+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
34+
35+
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
36+
--> $DIR/dyn-pos.rs:5:16
37+
|
38+
LL | fn foo(x: &dyn async Fn()) {}
39+
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
40+
|
41+
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>
42+
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
43+
|
44+
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
45+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
46+
47+
error[E0038]: the trait `AsyncFn` cannot be made into an object
48+
--> $DIR/dyn-pos.rs:5:16
49+
|
50+
LL | fn foo(x: &dyn async Fn()) {}
51+
| ^^^^^^^^^^ `AsyncFn` cannot be made into an object
52+
|
53+
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>
54+
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
55+
|
56+
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
57+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
58+
59+
error[E0038]: the trait `AsyncFnMut` cannot be made into an object
60+
--> $DIR/dyn-pos.rs:5:16
61+
|
62+
LL | fn foo(x: &dyn async Fn()) {}
63+
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
64+
|
65+
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>
66+
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
67+
|
68+
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
69+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
70+
71+
error[E0038]: the trait `AsyncFn` cannot be made into an object
72+
--> $DIR/dyn-pos.rs:5:12
73+
|
74+
LL | fn foo(x: &dyn async Fn()) {}
75+
| ^^^^^^^^^^^^^^ `AsyncFn` cannot be made into an object
76+
|
77+
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>
78+
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
79+
|
80+
= note: the trait cannot be made into an object because it contains the generic associated type `CallFuture`
81+
::: $SRC_DIR/core/src/ops/async_function.rs:LL:COL
82+
|
83+
= note: the trait cannot be made into an object because it contains the generic associated type `CallMutFuture`
84+
85+
error: aborting due to 7 previous errors
86+
87+
For more information about this error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// FIXME(async_closures): This error message could be made better.
2+
3+
fn foo(x: impl async Fn()) -> impl async Fn() {}
4+
//~^ ERROR expected
5+
//~| ERROR expected
6+
//~| ERROR expected
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: expected one of `:` or `|`, found `)`
2+
--> $DIR/edition-2015.rs:3:26
3+
|
4+
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
5+
| ^ expected one of `:` or `|`
6+
7+
error: expected one of `(`, `)`, `+`, `,`, `::`, or `<`, found `Fn`
8+
--> $DIR/edition-2015.rs:3:22
9+
|
10+
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
11+
| -^^ expected one of `(`, `)`, `+`, `,`, `::`, or `<`
12+
| |
13+
| help: missing `,`
14+
15+
error: expected one of `(`, `+`, `::`, `<`, `where`, or `{`, found `Fn`
16+
--> $DIR/edition-2015.rs:3:42
17+
|
18+
LL | fn foo(x: impl async Fn()) -> impl async Fn() {}
19+
| ^^ expected one of `(`, `+`, `::`, `<`, `where`, or `{`
20+
21+
error: aborting due to 3 previous errors
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// edition:2018
2+
3+
struct F;
4+
5+
impl async Fn<()> for F {}
6+
//~^ ERROR expected type, found keyword `async`
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected type, found keyword `async`
2+
--> $DIR/impl-header.rs:5:6
3+
|
4+
LL | impl async Fn<()> for F {}
5+
| ^^^^^ expected type
6+
7+
error: aborting due to 1 previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// edition:2018
2+
// check-pass
3+
4+
#![feature(async_closure, type_alias_impl_trait)]
5+
6+
type Tait = impl async Fn();
7+
fn tait() -> Tait {
8+
|| async {}
9+
}
10+
11+
fn foo(x: impl async Fn()) -> impl async Fn() { x }
12+
13+
fn param<T: async Fn()>() {}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// edition:2018
2+
3+
fn main() {
4+
<_ as async Fn()>(|| async {});
5+
//~^ ERROR expected identifier, found keyword `async`
6+
//~| ERROR expected one of
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: expected identifier, found keyword `async`
2+
--> $DIR/method-call-pos.rs:4:11
3+
|
4+
LL | <_ as async Fn()>(|| async {});
5+
| ^^^^^ expected identifier, found keyword
6+
7+
error: expected one of `(`, `::`, `<`, or `>`, found `Fn`
8+
--> $DIR/method-call-pos.rs:4:17
9+
|
10+
LL | <_ as async Fn()>(|| async {});
11+
| ^^ expected one of `(`, `::`, `<`, or `>`
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)