]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0619.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0619.md
1 #### Note: this error code is no longer emitted by the compiler.
2
3 The type-checker needed to know the type of an expression, but that type had not
4 yet been inferred.
5
6 Erroneous code example:
7
8 ```compile_fail
9 let mut x = vec![];
10 match x.pop() {
11     Some(v) => {
12         // Here, the type of `v` is not (yet) known, so we
13         // cannot resolve this method call:
14         v.to_uppercase(); // error: the type of this value must be known in
15                           //        this context
16     }
17     None => {}
18 }
19 ```
20
21 Type inference typically proceeds from the top of the function to the bottom,
22 figuring out types as it goes. In some cases -- notably method calls and
23 overloadable operators like `*` -- the type checker may not have enough
24 information *yet* to make progress. This can be true even if the rest of the
25 function provides enough context (because the type-checker hasn't looked that
26 far ahead yet). In this case, type annotations can be used to help it along.
27
28 To fix this error, just specify the type of the variable. Example:
29
30 ```
31 let mut x: Vec<String> = vec![]; // We precise the type of the vec elements.
32 match x.pop() {
33     Some(v) => {
34         v.to_uppercase(); // Since rustc now knows the type of the vec elements,
35                           // we can use `v`'s methods.
36     }
37     None => {}
38 }
39 ```