compiler/rustc_error_codes/src/error_codes/E0284.md MARKDOWN 33 lines View on github.com → Search inside
1This error occurs when the compiler is unable to unambiguously infer the2return type of a function or method which is generic on return type, such3as the `collect` method for `Iterator`s.45For example:67```compile_fail,E02848fn main() {9    let n: u32 = 1;10    let mut d: u64 = 2;11    d = d + n.into();12}13```1415Here we have an addition of `d` and `n.into()`. Hence, `n.into()` can return16any type `T` where `u64: Add<T>`. On the other hand, the `into` method can17return any type where `u32: Into<T>`.1819The author of this code probably wants `into()` to return a `u64`, but the20compiler can't be sure that there isn't another type `T` where both21`u32: Into<T>` and `u64: Add<T>`.2223To resolve this error, use a concrete type for the intermediate expression:2425```26fn main() {27    let n: u32 = 1;28    let mut d: u64 = 2;29    let m: u64 = n.into();30    d = d + m;31}32```

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.