Closed
Description
This code:
fn sum_and_show(data: &[u32]) -> String {
data.iter().sum().to_string()
}
fn main() {
let s: String = sum_and_show(&[1, 2, 3]);
}
In rustc 1.20.0-nightly (b2c0707 2017-07-13) gives the error message:
error[E0619]: the type of this value must be known in this context
--> ...\test.rs:2:5
|
2 | data.iter().sum().to_string()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The error message doesn't point to the exact location of the problem. The correct code is:
data.iter().sum::<u32>().to_string()
So probably I'd like an error message like:
error[E0619]: the type of this value must be known in this context
--> ...\test.rs:2:5
|
2 | data.iter().sum().to_string()
| ^^^^^
Even better: I'd like Rustc to infer the right type for sum(), not require a type hint there and compile the original code.
Metadata
Metadata
Assignees
Labels
No labels