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

Feature request: quick fix to update const array size #13999

Closed
IFcoltransG opened this issue Jan 21, 2023 · 3 comments
Closed

Feature request: quick fix to update const array size #13999

IFcoltransG opened this issue Jan 21, 2023 · 3 comments
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request S-actionable Someone could pick this issue up and work on it right now

Comments

@IFcoltransG
Copy link

If I declare a const array, I need to give it a specific size, in this case 2.

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

When I add or remove a number from the initialiser, the compiler will complain that the listed array length is now wrong. It would be convenient to have a quick fix, which amends the explicit size to match the true number of items in the array.

Here's an example of the fix that I would like applied, changing the array type from [u8; 2] to [u8; 3].

const NUMBERS: [u8; 2] = [
  10,
  20,
  30
]; // mismatched types, expected array `[u8; 2]`, found array `[u8; 3]`

->

const NUMBERS: [u8; 3] = [
  10,
  20,
  30
];
@lnicola
Copy link
Member

lnicola commented Jan 21, 2023

Bah. If you write [u8; _], rustc will offer a suggestion, but not if you put in the wrong value.

@lnicola
Copy link
Member

lnicola commented Jan 21, 2023

Filed rust-lang/rust#107156.

@lnicola lnicola added S-actionable Someone could pick this issue up and work on it right now A-diagnostics diagnostics / error reporting C-feature Category: feature request labels Jan 21, 2023
@HKalbasi
Copy link
Member

Closing since it is now implemented in rustc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

3 participants