Skip to content

Trait "is not implemented for the type" with associated types and blanket impls #19479

Closed
@comex

Description

@comex

This may be a duplicate of #19058, but the code looks somewhat different - there is only one associated type. Here, the idea is to blanket impl a trait with an associated type based on another.

#![feature(associated_types)]
trait Base {}
trait AssocA {
    type X: Base;
}
trait AssocB {
    type Y: Base;
}
impl<T: AssocA> AssocB for T {
    type Y = <T as AssocA>::X;
}

fn main() {}

produces

asty.rs:9:1: 11:2 error: the trait `Base` is not implemented for the type `X`
asty.rs:9 impl<T: AssocA> AssocB for T {
asty.rs:10     type Y = <T as AssocA>::X;
asty.rs:11 }
asty.rs:9:1: 11:2 note: the trait `Base` must be implemented because it is required by `AssocB`
asty.rs:9 impl<T: AssocA> AssocB for T {
asty.rs:10     type Y = <T as AssocA>::X;
asty.rs:11 }

which is clearly wrong, since AssocA::X is required to implement Base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions