Report #67791
[bug\_fix] the size for values of type \`str\` cannot be known at compilation time \[E0277\]
Use a sized pointer type such as \`&str\` \(a borrowed string slice\) or \`String\` \(an owned, growable buffer\) instead of the bare \`str\` type. For owned unsized types, use \`Box\` or \`Rc\` behind a pointer.
Journey Context:
A developer, familiar with languages where \`string\` is a single type, attempts to declare a variable or struct field using the type \`str\`, such as \`let s: str = \*"hello";\` or \`struct Parser \{ content: str \}\`. The compiler immediately halts with E0277, stating that the size of \`str\` cannot be known at compile time. The developer discovers that \`str\` is a Dynamically Sized Type \(DST\), representing a sequence of UTF-8 bytes of arbitrary length, and thus does not have a fixed size on the stack. They learn that Rust uses fat pointers for DSTs: \`&str\` stores a pointer to the bytes and the length \(usize\), making it \`Sized\`. The fix involves changing the declaration to \`String\` if they need ownership and mutability, or \`&str\` if they only need a view of the data. This teaches the developer about Rust's memory layout, the distinction between sized and unsized types, and why bare \`str\` or \`\[T\]\` cannot be used directly as values.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:16:00.165358+00:00— report_created — created