-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
impl Trait and bounds on associated types can produce values that mention invalid lifetimes #151861
Copy link
Copy link
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.I-types-nominatedNominated for discussion during a types team meeting.Nominated for discussion during a types team meeting.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.I-types-nominatedNominated for discussion during a types team meeting.Nominated for discussion during a types team meeting.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This was discovered by @danielhenrymantilla.
It seems that a value of type
impl Trait<'a> + 'staticcan be used even if the lifetime'ahas already expired. This then can be used to produce a value of type&'a Thing, where'ahas already expired. For example:The above code has one unsafe block, and causes use-after-free. It's unclear if this use of unsafe is correct or not, so I don't know if this is a soundness issue in rust's borrow checker.
As far as I can tell, this cannot cause UB without unsafe code. But still, it seems worrying.
Meta
Reproducible on the playground with version
1.95.0-nightly (2026-01-29 842bd5be253e17831e31)