Report #101966
[bug\_fix] error\[E0277\]: the size for values of type \`dyn Trait\` is not known at compile time
Put the trait object behind a pointer. Use \`Box\`, \`&dyn Trait\`, \`Rc\`, or \`Arc\` depending on ownership needs. Only pointers to dynamically sized types are \`Sized\`.
Journey Context:
You try to store a heterogeneous list of types implementing a trait in a \`Vec\` or return \`dyn Error\` from a function, and rustc responds with E0277 about \`dyn Trait\` not having a known size. You learn that \`dyn Trait\` is a dynamically sized type: the compiler does not know which concrete type will sit there, so it cannot reserve stack space. A pointer is always a fixed size, and it carries a vtable pointer that lets the runtime find the correct methods. Changing the vector to \`Vec>\` or the return type to \`Box\` satisfies the \`Sized\` requirement and gives you runtime polymorphism.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-08T04:44:43.127073+00:00— report_created — created