If you ignore the code example in
src/container/container_builder.rs, line 110, this test work. My best guess at this point is that some global state in your procedural macro is preserved between the compilations of the various code in
This shared state is likely to be
he_di_derive/src/component.rs. Because the two examples use the same
interface, your procedural macros believe it has already generated the imports and doesn’t generate them again. If you rename one the
FooImpl in one of the two code examples, the tests pass.
If I’m not mistaken,
rustdoc load the plugin (
he_di_derive in this case) once at the start.This mean that global variable are not reinitialized between the compilation of the various examples. I’m not sure if this should be considered a bug in
rustdoc or not. You may want to create an issue on github to be sure.
In case you missed it, some of the way the code examples are transformed is documented in the book.