]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0284.md
Rollup merge of #107086 - clubby789:bootstrap-lock-pid-linux, r=albertlarsan68
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0284.md
1 This error occurs when the compiler is unable to unambiguously infer the
2 return type of a function or method which is generic on return type, such
3 as the `collect` method for `Iterator`s.
4
5 For example:
6
7 ```compile_fail,E0284
8 fn main() {
9     let n: u32 = 1;
10     let mut d: u64 = 2;
11     d = d + n.into();
12 }
13 ```
14
15 Here we have an addition of `d` and `n.into()`. Hence, `n.into()` can return
16 any type `T` where `u64: Add<T>`. On the other hand, the `into` method can
17 return any type where `u32: Into<T>`.
18
19 The author of this code probably wants `into()` to return a `u64`, but the
20 compiler can't be sure that there isn't another type `T` where both
21 `u32: Into<T>` and `u64: Add<T>`.
22
23 To resolve this error, use a concrete type for the intermediate expression:
24
25 ```
26 fn main() {
27     let n: u32 = 1;
28     let mut d: u64 = 2;
29     let m: u64 = n.into();
30     d = d + m;
31 }
32 ```