Trait implementation in sister crate in same workspace?

Hello there !

I'm suggeling because cargo/rustc say I've not implemented my trait on my struct.
I don't understand this, because I think I made this.
Perhaps it's because it is implemented in a "sister" external crate in my cargo workspace ?

Here is all the workspace code demo in order to reproduce this error :

And there is the error :

> cargo test               
   Compiling demo_lib v0.1.0 (\demo\demo_lib)
error[E0277]: the trait bound `MyImplement: MyTrait` is not satisfied
  --> demo_lib\src\
10 |         MyTrait::my_function(&mut an_implement, Arguments {}),
   |         -------------------- ^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `MyImplement`
   |         |
   |         required by a bound introduced by this call

For more information about this error, try `rustc --explain E0277`.
error: could not compile `demo_lib` due to previous error

Greetings !

Looks like the circular dependencies problem.

When you compile the test inside demo_lib, you have the following system of crates:

  • demo_lib_test, the "binary" crate containing test (not real crate, but semantically similar);
  • which depends on demo_implement,
  • which depends on demo_lib and implements demo_lib::MyTrait,
  • but test expects demo_lib_test::MyTrait, which, from the compiler's point of view, is fully independent from the demo_lib::MyTrait (due to it being in semantically different crate).

Hello @Cerber-Ursi and thank you so much you took time to understand and answer to my problem :+1:

I guess you right and you point out an illogical issue in my code architecture.

The short version of this illogical case (but this is still not quite it) is I'm trying to test my impl right next to my trait definition (in crate demo_lib), instead testing it inside the same crate (demo_implement).

This is not quit it because I expected to define general tests on the trait behaviour (for all possible impl), but looks like standard Cargo tooling does not allow this.

I've worked around this problem in order to continue.