You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Diagnostics: suggest adding lifetime to trait object stored in struct #78547
A-diagnosticsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Fixing it involves adding a lifetime bound with dyn Iterator<Item = char> + 'a, but this syntax is not something a beginner would know. It would be nice if rustc suggested it.
The linked situation would trigger if someone tried to fix the original code by adding a lifetime to Thing and the dyn Trait, while not accounting for that change in new:
implThing<'_>{pubfnnew(string:&str) -> Self{Thing{//~ ERROR: lifetime may not live long enoughchars:Box::new(string.chars()),}}}
A-diagnosticsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
estebank commentedon Dec 28, 2022
Triage: no change
estebank commentedon Oct 22, 2026
Related but not the same: #101393
The linked situation would trigger if someone tried to fix the original code by adding a lifetime to
Thingand thedyn Trait, while not accounting for that change innew:Rollup merge of rust-lang#164776 - estebank:short-lifetime-in-return-…
Rollup merge of rust-lang#164776 - estebank:short-lifetime-in-return-…
Rollup merge of rust-lang#164776 - estebank:short-lifetime-in-return-…
Unrolled build for #164776 in rollup 165002
Rollup merge of #164776 - estebank:short-lifetime-in-return-expr-2, r…