Report #13971
[bug\_fix] the size for values of type \`str\` cannot be known at compilation time or the trait \`Sized\` is not implemented for \`\[T\]\`
Use \`&str\` instead of \`str\`, \`Box\` for owned DSTs, or \`Vec\` instead of \`\[T\]\` for owned sequences. For generic functions that must accept DSTs \(like \`fn foo\(t: &T\)\`\), add \`?Sized\` to relax the implicit \`Sized\` bound. The root cause is that \`str\` and \`\[T\]\` are Dynamically Sized Types \(DSTs\) whose size is unknown at compile time, requiring them to be behind a pointer \(reference, Box, Arc, etc.\).
Journey Context:
You're refactoring code to be generic. You write \`fn print\(data: str\)\` thinking it accepts strings. Compiler says size not known. You try \`fn print\(data: T\)\` where \`T\` is \`str\` but same issue. You realize \`str\` is unsized. You change to \`&str\` and it works. Later, you write a trait \`trait Display\` and want \`fn show\(t: T\)\` to accept \`str\` via \`&str\`, but it won't work because \`&str\` doesn't implement \`Display\` if \`str\` doesn't, or because of Sized bounds. You learn about \`?Sized\`: \`fn show\(t: &T\)\`. Now \`&str\` works because the reference is Sized even when T is not. This is crucial for writing generic code that accepts slices or trait objects.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:18:16.774413+00:00— report_created — created