Skip to content

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

Closed
@IFcoltransG

Description

@IFcoltransG

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
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsdiagnostics / error reportingC-featureCategory: feature requestS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions