Skip to content

Rust cannot derive traits from associated types #34377

Closed
@ghost

Description

#[derive(Copy, Clone)]
pub struct Bar(<Bar as Foo>::Type);

#[derive(Copy, Clone)]
pub struct Baz(i8);

pub trait Foo {
    type Type;
}

impl Foo for Bar {
    type Type = i8;
}

fn main() {
    println!("Ha, I don't compile!");
}
<anon>:1:10: 1:14 error: the trait `Copy` may not be implemented for this type; field `<unnamed_field>` does not implement `Copy` [E0204]
<anon>:1 #[derive(Copy, Clone)]

Baz is fine, Bar fails.

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