Closed
Description
I ran into a case with generated code today where I believe the compiler is giving a false error trying to verify a trait implementation.
Given a crate foo
defined as:
// foo.rs
pub trait Foo {}
and then a consumer crate bar
:
// bar.rs
struct A;
trait B {
type C;
}
impl B for A {
type C = MyType;
}
struct MyType;
impl foo::Foo for <A as B>::C {}
when compiled this yields:
$ rustc +nightly foo.rs --crate-type lib
$ rustc +nightly bar.rs --crate-type lib --extern foo=libfoo.rlib
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> bar.rs:13:1
|
13 | impl foo::Foo for <A as B>::C {}
| ^^^^^^^^^^^^^^^^^^-----------
| | |
| | `<A as B>::C` is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead
error: aborting due to previous error
For more information about this error, try `rustc --explain E0117`.
I don't believe that the error here is accurate since A
, B
, C
, and MyType
are all local to the crate and the compiler would ideally follow the projection to conclude that this trait implementation is valid.