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

I read the tutorial at above link, when i wrote this code in

pub mod client;
mod network;

pub mod outermost {
    pub fn middle_function() {}

    fn middle_secret_function() {}

    mod inside {
        pub fn inner_function() {

        fn secret_function() {}

fn try_me() {

there is my lib tree:

β”œβ”€β”€ Cargo.lock
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ src
β”‚   β”œβ”€β”€
β”‚   β”œβ”€β”€
β”‚   β”œβ”€β”€
β”‚   └──

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/
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…

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