Skip to content

GAT: unconstrained lifetime in output when using GAT in fn type #77905

Open
@athre0z

Description

@athre0z
#![feature(generic_associated_types)]

trait Foo {
    type In<'a>;
}

struct Simple<'a>(std::marker::PhantomData<&'a u32>);

fn somefn_simple(f: for<'a> fn(Simple<'a>) -> Simple<'a>) {
    // compiles.
}

fn somefn_gat<T: Foo>(f: for<'a> fn(T::In<'a>) -> T::In<'a>) {
    // errors.
}

fn main() {}

I would expect somefn_gat to build just like somefn_simple does, however it currently results in this error:

warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(generic_associated_types)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types
  --> src/main.rs:13:51
   |
13 | fn somefn_gat<T: Foo>(f: for<'a> fn(T::In<'a>) -> T::In<'a>) {
   |                                                   ^^^^^^^^^

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0581`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

rustc --version --verbose:

rustc 1.48.0-nightly (ef663a8a4 2020-09-30)

Click here for playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-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