3
votes

I get why they must have constant size, but I don't get why that size must be known at compile time. Even C allows variable length arrays on the stack. What does this limitation help Rust with?

1
Even C allows — C allows lots of bad things. The fact that a language allows something doesn't make it good. - Shepmaster
@Shepmaster: the question has to do with what is the technical reason for that choice, not about how useful VLAs seem - blue_note
Sure, but there has to be at least one good use for a feature, otherwise the technical reason could be "there's no good reason to support this". I'm not making a statement that VLAs are or are not useful, just that saying "C can do X" is a weak argument. - Shepmaster
C11 remove this feature for a reason :p - Stargateur

1 Answers

4
votes

Even C allows variable length arrays on the stack.

C can relatively easily support this because of its trivial semantics.

When you have to call destructors/drop, this is far less trivial, so Rust didn't initially support it because it's effort to implement and doesn't give all that much of a benefit.

Eventually, Rust will support this (and already does on nightly) thanks to RFC 1909 — unsized rvalues.