Skip to content

Intervening type alias of GAT to causes incorrect E0581 #85533

Closed
@elidupree

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.

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. GATsGATs-triagedIssues using the `generic_associated_types` feature that have been triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions