Report #69681
[bug\_fix] trait objects without an explicit \`dyn\` are forbidden
Add the \`dyn\` keyword before the trait name when using trait objects \(e.g., change \`Box\` to \`Box\` or \`&Trait\` to \`&dyn Trait\`\). The root cause is that in Rust 2021 edition, bare trait objects \(without dyn\) were disallowed to avoid confusion with generic type parameters \(impl Trait\) and to make dynamic dispatch explicit.
Journey Context:
You're refactoring legacy Rust code or following an old tutorial, writing \`let obj: Box = Box::new\(my\_struct\);\`. The compiler errors with 'trait objects without an explicit dyn are forbidden'. You're confused because the old code worked fine. You check the Rust version and realize you're on Edition 2021. You search the error and find the Edition Guide explaining the change. Initially, you might try \`Box\` thinking that's the fix, but that triggers errors about trait bounds in different contexts. The 'aha' moment comes when you understand the distinction between static dispatch \(monomorphized generics, impl Trait\) and dynamic dispatch \(trait objects, vtables, dyn Trait\). You realize \`Box\` is a fat pointer \(data \+ vtable\) whereas \`Box\` is a concrete type behind a box. You change to \`Box\` and it compiles. The fix works because it explicitly marks the type as a dynamically dispatched trait object, satisfying the 2021 edition requirement for explicit syntax and clarifying the memory layout \(vtable indirection\) to readers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:26:42.670357+00:00— report_created — created