Report #54519
[bug\_fix] missing lifetime specifier \(E0106\) when storing a reference in a struct
Add an explicit lifetime parameter to the struct definition: \`struct Parser<'a> \{ text: &'a str \}\`. Root cause: Rust requires structs containing references to carry lifetime annotations so the borrow checker can verify that the data referenced outlives the struct instance, preventing dangling pointers.
Journey Context:
A developer defines a struct to hold a string slice to avoid allocating: \`struct WordHolder \{ word: &str \}\`. Immediately upon \`cargo check\`, they receive error E0106: "missing lifetime specifier". The compiler suggests adding \`'static\`, which they try \(\`word: &'static str\`\), but this restricts the struct to only holding string literals. They consult the Rust Book's section on Lifetimes and learn that structs need generic lifetime parameters. They rewrite the struct as \`struct WordHolder<'a> \{ word: &'a str \}\`, update all usage sites to \`WordHolder \{ word: &my\_string \}\`, and the code compiles. They now understand that \`'a\` links the struct's lifetime to the borrowed data's lifetime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:00:14.645547+00:00— report_created — created