book
book copied to clipboard
Chapter 7.2 Defining Modules to Control Scope and Privacy
- [x] I have checked the latest
main
branch to see if this has already been fixed - [x] I have searched existing issues and pull requests for duplicates
URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html#modules-quick-reference
Description of the problem: The book states that:
Declaring modules: In the crate root file, you can declare a new module named, say, “garden”, with mod garden;. The compiler will look for the code inside the module in these places:
- Inline, directly following mod garden, within curly brackets instead of the semicolon
- In the file src/garden.rs
- In the file src/garden/mod.rs
Yes, it's true that the compiler will search these 3 places. But it's better to clarify that only one of them is allowed. For example, you can't have both src/garden.rs
and src/garden/mod.rs
. As a new Rust user, when I was reading this piece of text, I don't know only one of them is allowed and the compiler tells me error[E0761]: file for module
table found at both "src\table\table.rs" and "src\table\table\mod.rs"
.
Suggested fix: Make it clear that only one one option is allowed.