error[E0433]: failed to resolve: could not find `outermost` in `{{root}}`

#1

https://doc.rust-lang.org/1.30.0/book/second-edition/ch07-02-controlling-visibility-with-pub.html#fixing-the-errors

I read the tutorial at above link, when i wrote this code in lib.rs:

pub mod client;
mod network;

pub mod outermost {
    pub fn middle_function() {}

    fn middle_secret_function() {}

    mod inside {
        pub fn inner_function() {
            ::outermost::middle_secret_function();
        }

        fn secret_function() {}
    }
}

fn try_me() {
    //outermost::middle_function();
    //outermost::middle_secret_function();
    //outermost::inside::inner_function();
    //outermost::inside::secret_function();
}

there is my lib tree:

communicator
├── Cargo.lock
├── Cargo.toml
├── src
│   ├── client.rs
│   ├── lib.rs
│   ├── main.rs
│   └── network.rs

and then cargo build, it error:

   Compiling communicator v0.1.0 (/Users/netcan/Workspace/Rust/communicator)
error[E0433]: failed to resolve: could not find `outermost` in `{{root}}`
  --> src/lib.rs:11:15
   |
11 |             ::outermost::middle_secret_function();
   |               ^^^^^^^^^ could not find `outermost` in `{{root}}`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
error: Could not compile `communicator`.

To learn more, run the command again with --verbose.

can someone tell me why it error…

#2

Presumably you’ve specified edition = "2018" in Cargo.toml. In that case, you should replace ::outermost::middle_secret_function() with crate::outermost::middle_secret_function().

If you’d like to continue using the 2018 edition, consider reading the Rust edition guide; it has a section on this bit in particular (i.e. crate prefix) here, but read the other parts as well.

1 Like