Closed
Description
Given the following code: playground link
fn main() {
let x: [i32; 3] = (0i32..3).collect();
}
The current output is:
error[E0277]: a value of type `[i32; 3]` cannot be built since `[i32; 3]` has no definite size
--> src/main.rs:2:33
|
2 | let x: [i32; 3] = (0i32..3).collect();
| ^^^^^^^ try explicitly collecting into a `Vec<i32>`
|
= help: the trait `FromIterator<i32>` is not implemented for `[i32; 3]`
note: required by a bound in `collect`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error
This output mirrors the error for slices, "a value of type [i32]
cannot be built since [i32]
has no definite size", and I suspect this was over-corrected in error.
I don't know what the best hints would be for someone trying to collect into an array; whether hinting to collect into a vec and use try_into
, or to construct a [();N]
and map
the array.