Fixed length arrays - Why (Question about syntax)

If I have the code:

const fixed_thing[usize;3] = [1,2,3,4];

I get error:

29 |     const fixed_thing:[usize;3] = [1,2,3,4];
   |                                   ^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 4 elements
   = note: expected type `[usize; 3]`
              found type `[usize; 4]`

Fair enough. Except why can I not write:

    const fixed_thing:[usize;] = [1,2,3,4];

The compiler has all the information that it needs to determine the size of the object. What am I missing?

This has been asked before

and const generics may help with it

1 Like