Skip to content

[T; N] has no definite size #96461

Closed
@Zoybean

Description

@Zoybean

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.

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions