x.N
is too restricting lexically, you can't put an arbitrary constant there (which would be useful with variadics).
Adding hacks to x[EXPR]
to detect x[CONST_EXPR]
and treat it differently (avoid overloading, switch to field access semantics) doesn't feel like a good solution to me (this is also a breaking change technically).
Perhaps a separate non-overloadable operator x.[CONST_EXPR]
would be more appropriate for compile-time indexing, but the motivation is probably not large enough until variadics arrive.
The separate operator could be used with arbitrary structs as well
struct S { field: u8 }
let s = S { field: 10 };
let z = s.[0]; // z = 10
except that use from other crates need to be prohibited by default to allow arbitrary field reordering without causing compatibility issues.