The following code:
#![feature(specialization)]
struct BadStruct {
err: MissingType
}
trait MyTrait<T> {
fn foo();
}
impl<T, D> MyTrait<T> for D {
default fn foo() {}
}
impl<T> MyTrait<T> for BadStruct {
fn foo() {}
}
gives the following errors:
error[E0412]: cannot find type `MissingType` in this scope
--> src/lib.rs:4:10
|
4 | err: MissingType
| ^^^^^^^^^^^ not found in this scope
error[E0119]: conflicting implementations of trait `MyTrait<_>` for type `BadStruct`:
--> src/lib.rs:15:1
|
11 | impl<T, D> MyTrait<T> for D {
| --------------------------- first implementation here
...
15 | impl<T> MyTrait<T> for BadStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `BadStruct`
error: aborting due to 2 previous errors
For some reason, the fact that the definition of BadStruct has an error (MissingType is not defining) causes a 'conflicting implementations' error to be emitted when BadStruct has a specialized impl. If MissingType is changed to a type which actually exists (e.g. ()), the 'conflicting implementations' error disappears.
I found this when working on rustc - a missing use statement caused 30 spurious specialization-related errors to be emiited, which all disappeared when I added the missing import.
The following code:
gives the following errors:
For some reason, the fact that the definition of
BadStructhas an error (MissingTypeis not defining) causes a 'conflicting implementations' error to be emitted whenBadStructhas a specialized impl. IfMissingTypeis changed to a type which actually exists (e.g.()), the 'conflicting implementations' error disappears.I found this when working on
rustc- a missingusestatement caused 30 spurious specialization-related errors to be emiited, which all disappeared when I added the missing import.