Skip to content

Spurious "downstream crates may implement trait ..." #50238

Open
@glandium

Description

@glandium

Consider the following code, close to the one in #50237:

#![crate_type="lib"]

use std::marker::PhantomData;

trait Foo {
    type Type: Qux<Self>;
}

struct Bar<T>(PhantomData<T>);

trait Qux<T> {}

impl<T: Foo<Type=U>, U: Qux<T>> From<U> for Bar<T> {
    fn from(t: U) -> Self {
        Bar(PhantomData)
    }
}

This fails to build with:

error[E0119]: conflicting implementations of trait `std::convert::From<Bar<_>>` for type `Bar<_>`:
  --> src/lib.rs:13:1
   |
13 | impl<T: Foo<Type=U>, U: Qux<T>> From<U> for Bar<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: conflicting implementation in crate `core`:
           - impl<T> std::convert::From<T> for T;
   = note: downstream crates may implement trait `Qux<_>` for type `Bar<_>`

But how can a downstream crate implement Qux<_> for Bar<_>?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-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