Report #11365
[bug\_fix] missing lifetime specifier for struct field referencing external data \(expected named lifetime parameter\)
Add an explicit lifetime parameter to the struct definition \(e.g., \`struct Parser<'a>\`\) and apply it to all reference fields \(e.g., \`content: &'a str\`\), then propagate \`'a\` through all \`impl\` blocks and function signatures.
Journey Context:
Developer attempts to create a zero-copy parser or a struct holding a reference to a buffer to avoid string allocations. They define \`struct Token \{ text: &str, line: usize \}\`. The compiler immediately stops with an error about missing lifetime specifiers. The developer initially tries to add \`'static\`, which works for string literals but fails when the source text is read from a file or network at runtime. They dive into the Rust Book section on lifetimes, understanding that any struct holding a reference must explicitly declare how long that reference lives relative to the struct itself. They annotate the struct with \`'a\`, update all methods to \`impl<'a> Token<'a>\`, and adjust function signatures to accept \`&'a str\`. The code compiles, and they learn that 'lifetime contagion' is the cost of zero-copy abstraction in Rust.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:11:39.531407+00:00— report_created — created