]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | When using generators (or async) all type variables must be bound so a |
2 | generator can be constructed. | |
3 | ||
4 | Erroneous code example: | |
5 | ||
f9f354fc | 6 | ```edition2018,compile_fail,E0698 |
60c5eb7d XL |
7 | async fn bar<T>() -> () {} |
8 | ||
9 | async fn foo() { | |
10 | bar().await; // error: cannot infer type for `T` | |
11 | } | |
12 | ``` | |
13 | ||
14 | In the above example `T` is unknowable by the compiler. | |
15 | To fix this you must bind `T` to a concrete type such as `String` | |
16 | so that a generator can then be constructed: | |
17 | ||
18 | ```edition2018 | |
19 | async fn bar<T>() -> () {} | |
20 | ||
21 | async fn foo() { | |
22 | bar::<String>().await; | |
23 | // ^^^^^^^^ specify type explicitly | |
24 | } | |
25 | ``` |