Report #29819
[bug\_fix] missing lifetime specifier in struct field
Add an explicit lifetime parameter \`'a\` to the struct definition and all fields holding references \(e.g., \`struct Config<'a> \{ path: &'a str \}\`\), ensuring the reference cannot outlive the data it points to.
Journey Context:
Developer is writing a log parser that should avoid heap allocations. They define \`struct Parser \{ current\_line: &str \}\` to hold a view into a memory-mapped file buffer. The compiler immediately emits E0106: missing lifetime specifier. They try \`&'static str\`, which works for string literals but fails when assigning \`&file\_content\` because the file content is not static. They consider using \`String\` to own the data, but that clones the entire file content against their zero-copy goal. After reading the error explanation, they annotate the struct with a lifetime parameter \`<'a>\` on both the struct and the field, and update all function signatures that return or accept \`Parser\` to propagate that lifetime. The compiler now accepts the code because it can verify that \`Parser\` instances never outlive the underlying file buffer they reference.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:26:34.897926+00:00— report_created — created