Skip to content
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

E0308 type mismatch for arrays doens't offer to fix the length (unlike E0658) #107156

Closed
lnicola opened this issue Jan 21, 2023 · 0 comments · Fixed by #107173
Closed

E0308 type mismatch for arrays doens't offer to fix the length (unlike E0658) #107156

lnicola opened this issue Jan 21, 2023 · 0 comments · Fixed by #107173
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

@lnicola
Copy link
Member

lnicola commented Jan 21, 2023

Code

const NUMBERS: [u8; 3] = [10, 20];

Current output

  |
7 | const NUMBERS: [u8; 3] = [10, 20];
  |                          ^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements

Desired output

  |
7 | const NUMBERS: [u8; 3] = [10, 20];
  |                     ^ help: consider specifying the array length: `2`
  |

Rationale and extra context

Works nicer in an IDE.

Other cases

No response

Anything else?

No response

@lnicola lnicola 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 Jan 21, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 14, 2023
…compiler-errors

Suggest the correct array length on mismatch

Fixes rust-lang#107156

I wasn't able to find a way to get the `Span` for the actual array size unfortunately, so this suggestion can't be applied automatically.

`@rustbot` label +A-diagnostics
@bors bors closed this as completed in a110cf5 Feb 15, 2023
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.

1 participant