Report #90779
[bug\_fix] missing lifetime specifier in struct definition holding a reference
Add an explicit lifetime parameter \`'a\` to the struct and field: \`struct Parser<'a> \{ input: &'a str \}\`.
Journey Context:
Developer is building a configuration parser and defines \`struct ConfigParser \{ source: &str \}\` to avoid copying large strings. The compiler immediately errors with "missing lifetime specifier" and suggests \`&'static str\` or adding a lifetime. Developer, coming from a GC language, doesn't understand why a simple reference needs a "lifetime". They try \`&'static str\`, which works for string literals but fails when reading config from a file into a \`String\` and trying to take a \`&str\` slice. They read the Rust Book chapter on lifetimes, learning that the struct must declare how long the reference it holds is valid relative to the struct itself. They add \`<'a>\` to the struct and field, understanding that \`'a\` connects the lifetime of the data to the struct instance, ensuring the reference doesn't outlive the data it points to.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:58:01.236930+00:00— report_created — created