Skip to content

Associated type constraint fails, even if it implements requested trait #76407

Closed
@Mr-Andersen

Description

@Mr-Andersen

Associated type constraint fails, even if it implements requested trait. In the example below, requested trait is Marker, u32 implements it, <MyStruct as MyTrait>::Item<'a> == u32, but <MyStruct as MyTrait>::Item<'a>: Marker does not pass. (Everything is ok with <'a> removed)

The code:

#![allow(incomplete_features)]
#![feature(generic_associated_types)]

trait Marker {}

impl Marker for u32 {}

trait MyTrait {
    type Item<'a>;
}

struct MyStruct;

impl MyTrait for MyStruct {
    type Item<'a> = u32;
}

fn ty_check<T>()
where
    T: MyTrait,
    for<'a> T::Item<'a>: Marker
{}

fn main() {
    ty_check::<MyStruct>();
}

Meta

rustc --version --verbose:

rustc 1.48.0-nightly (cdc8f0606 2020-09-05)
binary: rustc
commit-hash: cdc8f0606d0f3c4f3866643382c8a5776d1bdaed
commit-date: 2020-09-05
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)C-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsrequires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions