0

My understanding is that extern crate foo; declarations in the root module are then importable in any submodule with use foo::bar. While this works in one submodule, it doesn't work in the other submodule. Any ideas why this might not work?

|--- main.rs
|--- module1
     |--- mod.rs
     |--- submod1.rs
|--- module2
     |--- mod.rs
     |--- submod2.rs

// main.rs
extern crate rustc_serialize;
mod module1;
mod module2;

// module1/mod.rs
mod submod1;

// module1/submod1.rs
use rustc_serialize::json; // WORKS

// module2/mod.rs
mod submod2;

// module2/submod2.rs
use rustc_serialize::json; // DOESN'T WORK

EDIT: I forgot that in my project, module1 is defined as a library crate, which detached it from the usual import namespaces

brandonchinn178
  • 519
  • 3
  • 20
  • 1
    Your example works for me with `rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)`. I did have to add an empty `main` method to main.rs. – Shepmaster Jun 04 '15 at 19:07
  • Hm you're right it does work... it doesn't work in the actual code though. There are `extern crate` statements in `module1/mod.rs`, though, does that affect it? – brandonchinn178 Jun 04 '15 at 19:13
  • 1
    Yes. This question is probably a dupe of http://stackoverflow.com/q/27653198/155423 then. – Shepmaster Jun 04 '15 at 19:15
  • Oh wait I figured it out. I defined `module1/mod.rs` to be a library crate in order to generate documentation – brandonchinn178 Jun 04 '15 at 19:19

0 Answers0