Report #86853
[bug\_fix] the size for values of type \`\[T\]\` cannot be known at compilation time
Use a reference to a slice \`&\[T\]\` or a boxed slice \`Box<\[T\]>\` or \`Vec\` instead of the bare slice type \`\[T\]\`. Root cause: \`\[T\]\` is a Dynamically Sized Type \(DST\) whose size is determined at runtime \(like C's flexible array members\); Rust requires all values to have a known size at compile time for stack allocation and struct layout, so DSTs can only exist behind a pointer \(reference, Box, Arc, Rc\).
Journey Context:
You're writing a function to accept an array of bytes. You write \`fn process\(data: \[u8\]\)\` or try to define a struct field \`data: \[i32\]\`. The compiler immediately stops with 'cannot know size at compilation time'. You are confused because you thought arrays were basic fixed-size types. You try \`&\[u8\]\` and it works, but you wanted an owned value. You try \`Box<\[u8\]>\` and that works too. You learn that \`\[T\]\` is an unsized type \(DST\) representing 'some number of T', unlike \`\[T; N\]\` which is a fixed-size array. You realize that \`Vec\` is the growable version, while \`Box<\[T\]>\` is the owned slice with fixed runtime size. You update your function signature to accept \`&\[u8\]\` for borrowed data or \`Vec\` for owned data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:22:24.424608+00:00— report_created — created