Skip to content

Lifetimes get replaced with 'static in Self within (return position) impl Trait. #53613

Closed
@eddyb

Description

@eddyb
#[derive(Copy, Clone)]
struct Invariant<'a>(std::marker::PhantomData<&'a mut &'a ()>);

impl<'a> Invariant<'a> {
    fn lazy_dup(self) -> impl Fn() -> (Invariant<'a>, Self) {
        || (self, self)
    }
}
error[E0308]: mismatched types
 --> src/lib.rs:6:19
  |
6 |         || (self, self)
  |                   ^^^^ lifetime mismatch
  |
  = note: expected type `Invariant<'static>`
             found type `Invariant<'a>`

I didn't write 'static anywhere - it comes from part of the implementation of impl Trait, and Self references lifetimes (from the impl header) "indirectly", hiding them from impl Trait logic.

cc @cramertj @oli-obk @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions