Why can't a variable own a string directly?

There is some confusion because there are two syntaxes: one for array types ([T; N]) and another for array literals filled with a given value ([value; N]) or a list of values ([value, ...]).

The array type can be used on the left of a binding declaration (let) just like str<T> would be. While array literals are used on the right of a binding, so that must be what you're referring to. Note that an array literal can also be used by itself as an expression.

We already have literal syntax for fixed sized strings: "...". If you also wanted a string literal with a repeated char, you'd have to invent some new syntax for it.

1 Like