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

doc/book/crates-and-modules.md: Doesn't explain where it's legal to declare a mod #38514

Closed
penguin42 opened this issue Dec 21, 2016 · 2 comments

Comments

@penguin42
Copy link

penguin42 commented Dec 21, 2016

Rust wont let me do (all in one src/)

main.rs:
mod image;

image.rs:
mod string; <<<< 'error: cannot declare a new module at this location'

string.rs:
whatever

I don't see anything in crates-and-modules.md that says it's not possible and/or why.
It does let me add the mod string; in the top level main.rs.
(as a new rust user it doesn't make much sense to me why you can't, since main/rs doesn't use string.rs, but image.rs, so why does main.rs care)

@pnkfelix
Copy link
Member

pnkfelix commented Dec 21, 2016

FYI The reason for this restriction is documented as part of rust-lang/rfcs#63 (RFC 63 text). In particular, the Motivation section of that RFC lays out an example that shows a footgun for new users when putting mod filename; into modules other than mod.rs/lib.rs

I agree that the Rust documentation in crates-and-modules.md should probably point out the restrictions on where mod filename; can be used explicitly.

@steveklabnik
Copy link
Member

We are not improving the existing book ourselves, as we're re-writing it over at https://github.com/rust-lang/book, and this chapter has completely changed. If you or anyone else would like to improve this, please send in a PR, and/or read the new book and file an issue over there if it's still deficient in this way. But we're not keeping bugs open that track problems with the book's text. Thanks!

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

No branches or pull requests

4 participants