Skip to content

No syntactic way to specify GATs with where bounds in where clauses #95268

Open
@joe-hauns

Description

@joe-hauns

Hi!

I was trying to use GATs in one of my projects, and ran into the following issue.

#![feature(generic_associated_types)]

trait ModuleConfig {

    type Type1;

    type Type2<'a>
        where Self::Type1: 'a;

}

trait ModuleConfigSpec<T>
    where Self: for<'a> ModuleConfig<
        Type2<'a> = &'a T
        >,
{ }

fn main() {
    println!("Hello, world!");
}

This code does not compile, because the for<'a> bound in ModuleConfigSpec is not restricted by a where Self::Type1: 'a, which makes sense.
But as there is no way to specify this where bound, this means that GATs with where bounds cannot be passed to traits as concrete arguments.
I expected it to be possible to specify where bounds locally for every GAT specified. Like in this case I expected to be able to write something like


trait ModuleConfigSpec<T>
    where Self: ModuleConfig<
        for<'a> Type2<'a> = &'a T where Self::Type1: 'a,
        >,
{ }

Interestingly the code complies if we replace trait ModuleConfigSpec by

fn takes_spec_module_config<M, T>() 
    where M: for<'a> ModuleConfig<
        Type2<'a> = &'a T
    >
{  }

which specifies the very same trait bounds.

Meta

rustc --version --verbose:

rustc 1.61.0-nightly (5f3700105 2022-03-22)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)GATs-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