Skip to content

Impls for a generic type with different type parameters conflict with each other. #20188

Closed
@vadimcn

Description

@vadimcn
struct Foo<T>(T);
struct A;
struct B;

impl Foo<A> {
    fn foo() {}
}
impl Foo<B> {
    fn foo() {}
}

fn main() {}

produces duplicate definition error for foo:

test.rs:9:2: 9:13 error: duplicate definition of value `foo`
test.rs:9       fn foo() {}
                ^~~~~~~~~~~
test.rs:6:2: 6:13 note: first definition of value `foo` here
test.rs:6       fn foo() {}
                ^~~~~~~~~~~
error: aborting due to previous error

Since Foo<A> and Foo<B> are different types, it seems that their impls should not be interfering with each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions