The code:
struct ErrorThing;
fn main() {
let input = vec![Ok(4_i32), Err(ErrorThing), Err(ErrorThing)];
let res: Result<i32, ErrorThing> = input.into_iter().collect();
}
Produces this error:
error[E0277]: a collection of type `i32` cannot be built from an iterator over elements of type `i32`
--> src/main.rs:6:58
|
6 | let res: Result<i32, ErrorThing> = input.into_iter().collect();
| ^^^^^^^ a collection of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
|
= help: the trait `std::iter::FromIterator<i32>` is not implemented for `i32`
= note: required because of the requirements on the impl of `std::iter::FromIterator<std::result::Result<i32, ErrorThing>>` for `std::result::Result<i32, ErrorThing>`
error: aborting due to previous error
The message sounds very strange because a collection with elements of type i32 certainly can be built from an iterator over elements of type i32. The real problem is that a value of type i32 cannot be unambiguously built from an iterator over elements of type i32, because a folding function would need to be provided for it to make sense.
In cases where you are trying to collect into a non-collection type, the message should use a different word, probably "value".
The code:
Produces this error:
The message sounds very strange because a collection with elements of type
i32certainly can be built from an iterator over elements of typei32. The real problem is that a value of typei32cannot be unambiguously built from an iterator over elements of typei32, because a folding function would need to be provided for it to make sense.In cases where you are trying to collect into a non-collection type, the message should use a different word, probably "value".