Skip to content

Intervening type alias of GAT to causes incorrect E0581 #85533

Description

@elidupree

This code [playground]:

#![feature(generic_associated_types)]

trait Trait {
    type Assoc<'a>;
}

type AssocAlias<'a, T> = <T as Trait>::Assoc<'a>;

fn works<'a, T: Trait>(entity: T::Assoc<'a>) -> &'a i32 {&5}
fn fails<'a, T: Trait>(entity: AssocAlias<'a, T>) -> &'a i32 {&5}

Produces the following error on 1.54.0-nightly (2021-05-19 f94942d):

error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types
  --> src/lib.rs:10:54
   |
10 | fn fails<'a, T: Trait>(entity: AssocAlias<'a, T>) -> &'a i32 {&5}
   |            

The version that uses T::Assoc directly works, but the one using the type alias (which should be identical) fails.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)C-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions