Skip to content

Rust detects a conflict between non-conflicting implementations of a trait #92894

Closed as not planned
@p-avital

Description

@p-avital

Hello,

When trying to do some type-fu in a much larger project, I stumbled on a conflict detection which shouldn't happen. Here's a minimal version of the issue:

struct A;
struct B;
trait Specializer {
    type Key;
}
trait Conflict {
    fn conflict(&self);
}
struct C<T>(T);
// A first implementation, note that `A` is a concrete type.
impl<T: Specializer<Key=A>> Conflict for C<T> {
    fn conflict(&self) {}
}
// A second implementation, note that `B` is also a concrete type.
// Since `T` can only impl `Specializer` once, no type can impl both `Specializer<Key=B>` and `Specializer<Key=A>`
impl<T: Specializer<Key=B>> Conflict for C<T> {
    fn conflict(&self) {}
}

Rust responds with

error[E0119]: conflicting implementations of trait `Conflict` for type `C<_>`

but the implementations don't have any intersection, and shouldn't conflict.

You can also check it out on this playground, where you can see that the conflict is also mis-detected on nightly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.T-compilerRelevant to the compiler 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