"unresolved imports" with circular dependency between modules

I have two files:

  • json.rs in which I call Builder, the structure defined in builder.rs
  • builder.rs in which I call Json, structure defined in json.rs

As you can see, there is a circular dependency between these two modules. Sometimes Rust seems to support circular dependencies, but for this case the compiler throws errors:

src/json/mod.rs:1:25: 1:31 error: unresolved import (maybe you meant `ToJson::*`?)
src/json/mod.rs:1 pub use self::to_json::{ToJson};
                                          ^~~~~~
src/json/builder.rs:2:18: 2:22 error: unresolved import (maybe you meant `Json::*`?)
src/json/builder.rs:2 use json::json::{Json, JsonEvent, Array, Object}; //commenting this line solve the dependency error

[...]

      

The code is located here in the json_mod branch. I tried to reproduce the problem in fewer lines of code, but the circular dependencies I created compiled correctly.

Something like 400 errors left after debugging - this is ok as I'm in the process of a huge code refactoring (breaking one file of ~ = 4000 lines into many files) and I still have a lot of work to do before getting it to work ...

+3


source to share


1 answer


Edit: great news, bug fix mentioned below! It has been fixed in Rust 1.4 or newer.



Glob ( use foo::*

) imports have a known bug where they are incompatible with circular imports. I would try to remove glob imports in both affected modules.

+3


source







All Articles