Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentially incorrect text in Chapter 7.4: Bringing Paths into Scope with the use Keyword #3447

Closed
Mindstormer619 opened this issue Dec 3, 2022 · 1 comment · Fixed by #3879

Comments

@Mindstormer619
Copy link

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • 7.4
    • Before this change, external code would have to call
  • I have checked the latest main branch to see if this has already been fixed, in this file:

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#bringing-paths-into-scope-with-the-use-keyword

Description of the problem:

The problem is in the segment: Before this change, external code would have to call the add_to_waitlist function by using the path restaurant::front_of_house::hosting::add_to_waitlist(). External code cannot call the add_to_waitlist() function because the front_of_house module is not marked pub. Code to demonstrate:

lib.rs

mod front_of_house {
    pub mod hosting {
        pub fn add_to_waitlist() {}
    }
}

use crate::front_of_house::hosting;

pub fn eat_at_restaurant() {
    hosting::add_to_waitlist();
}

main.rs

fn main() {
    backyard::front_of_house::hosting::add_to_waitlist(); // does not compile
}

Error:

minds@Zero-Requiem MINGW64 /d/Workspace/Rust/RustBook/backyard (main)
$ cargo c
    Checking backyard v0.1.0 (D:\Workspace\Rust\RustBook\backyard)
error[E0603]: module `front_of_house` is private
 --> src\main.rs:2:15
  |
2 |     backyard::front_of_house::hosting::add_to_waitlist();
  |               ^^^^^^^^^^^^^^ private module
  |
note: the module `front_of_house` is defined here
 --> d:\Workspace\Rust\RustBook\backyard\src\lib.rs:1:1
  |
1 | mod front_of_house {
  | ^^^^^^^^^^^^^^^^^^

Suggested fix:

pub needs to be added before mod front_of_house.

@chriskrycho
Copy link
Contributor

Good catch! I just opened #3879 to fix it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants