Skip to content

[T; N] has no definite size #96461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Zoybean opened this issue Apr 27, 2022 · 0 comments · Fixed by #96466
Closed

[T; N] has no definite size #96461

Zoybean opened this issue Apr 27, 2022 · 0 comments · Fixed by #96466
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Zoybean
Copy link

Zoybean commented Apr 27, 2022

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.

@Zoybean Zoybean added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 27, 2022
@compiler-errors compiler-errors self-assigned this Apr 27, 2022
@bors bors closed this as completed in 6f6fe3e Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants