Skip to content

E0581/E0582 (lifetime not found in input type) occurs even when the lifetime is in traits used as inputs #86702

Open
@Manishearth

Description

@Manishearth
trait Yokeable<'a>: 'static {
    type Output: 'a;
}

fn project<Y, P, F>(f: F)
    where Y: for<'a> Yokeable<'a>,
        P: for<'a> Yokeable<'a>,
        F: for<'a> FnOnce(<Y as Yokeable<'a>>::Output) -> <P as Yokeable<'a>>::Output {}
fn project_fn<Y, P>(f: for<'a> fn(<Y as Yokeable<'a>>::Output) -> <P as Yokeable<'a>>::Output)
    where Y: for<'a> Yokeable<'a>,
            P: for<'a> Yokeable<'a> {}

fn main() {}

(playpen, also tested on rustc 1.54.0-nightly (fe72845f7 2021-05-16))

produces

   Compiling playground v0.0.1 (/playground)
error[E0582]: binding for associated type `Output` references lifetime `'a`, which does not appear in the trait input types
  --> src/main.rs:10:59
   |
10 |         F: for<'a> FnOnce(<Y as Yokeable<'a>>::Output) -> <P as Yokeable<'a>>::Output
   |                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types
  --> src/main.rs:14:67
   |
14 | fn project_fn<Y, P>(f: for<'a> fn(<Y as Yokeable<'a>>::Output) -> <P as Yokeable<'a>>::Output)
   |                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

The lifetime is used in the inputs, just behind a trait.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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