Skip to content

Unrecognized associated type bound on another associated type #24159

Closed

Description

trait Bar<T> { fn dummy(&self); }
trait Car<T> { fn dummy(&self); }

trait Foo {
    type A;
    type B: Bar<Self::A>;
    type C: Car<Self::A>;

    fn get_b(&self) -> &Self::B;
}

fn test_bar<A, B: Bar<A>>(_: &B) {}

fn test<A, F: Foo<A=A>>(f: &F) {
    test_bar(f.get_b());
}

Gives me:

<anon>:15:16: 15:23 error: the trait `Bar<A>` is not implemented for the type `<F as Foo>::B` [E0277]
<anon>:15     test_bar(f.get_b());
                         ^~~~~~~
<anon>:15:16: 15:23 error: the trait `Car<A>` is not implemented for the type `<F as Foo>::C` [E0277]
<anon>:15     test_bar(f.get_b());
                         ^~~~~~~
error: aborting due to 2 previous errors
playpen: application terminated with error code 101

There is a workaround:

fn test<A, B: Bar<A>, C: Car<A>, F: Foo<A=A, B=B, C=C>>(f: &F) {
    test_bar(f.get_b());
}

But it's ugly and should not be necessary.

We hit this problem a lot with gfx::Device, and I'd like to see cleaner use of it without explicit CommandBuffer bounds that we use as a workaround.

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

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priorityT-langRelevant to the language 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