]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0698.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0698.md
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
6 ```edition2018,compile_fail,E0698
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 ```