Open
Description
The following code:
trait Foo {}
impl<T: Foo> std::fmt::Display for T {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
Ok(())
}
}
produces the following compiler output:
error[E0119]: conflicting implementations of trait `std::fmt::Display` for type `&_`:
--> src/main.rs:3:1
|
3 | impl<T: Foo> std::fmt::Display for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<'a, T> std::fmt::Display for &'a T
where T: std::fmt::Display, T: ?Sized;
= note: downstream crates may implement trait `Foo` for type `&_`
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`); only traits defined in the current crate can be implemented for a type parameter
--> src/main.rs:3:1
|
3 | / impl<T: Foo> std::fmt::Display for T {
4 | | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
5 | | Ok(())
6 | | }
7 | | }
| |_^
error: aborting due to 2 previous errors
While there might be legitimate reasons why this is not allowed, the note is wrong: the trait Foo
is not public, a downstream can't possibly implement it for some type.