-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Guide new users to add use super::*;
to mod test
#10706
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon. Please see the contribution instructions for more information. |
Thinking about this some more, I think adding something for users to uncomment only solves a symptom of the issue and not the issue itself. I think the main issue is the error message from rustc (which appears to be generated in this function). It might be a better idea (and a harder change), to update the error message to include Something like:
I mocked this from here I think one of the maintainers may have more insight than I do on the route to go about this |
@epage - followed your second suggestion, thought it was the clearest. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm fine with this. The new template does not make a material difference in the boiletplate a user has to delete while it better teaches a user how the existing boilerplate would work.
I'm assuming this is small enough not to need an FCP but if anyone from the cargo team disagrees, we can always revert it and go through an FCP
@bors r+ |
📌 Commit 754a5bf has been approved by |
☀️ Test successful - checks-actions |
rust-lang/cargo#10706 switched the `cargo init --lib`-generated src/lib.rs to use a function and `use super::*;` inside the `mod test`. This makes it easier for new users to write their own functions and add tests, as it means the tests can refer to the new functions without any extra work, and without rustc asking them to add explicit `use`s for each new thing they add. This PR updates the parts of the book that use this src/lib.rs and similar examples, to match the new output of `cargo init --lib`, and to additionally help guide users to using `use super::*;` inside their `mod test`s. There is one non-example change, which is to update the wording in src/ch11-01-writing-tests.md to better reflect the new content in the associated example.
Update cargo 5 commits in 39ad1039d9e3e1746177bf5d134af4c164f95528..38472bc19f2f76e245eba54a6e97ee6821b3c1db 2022-05-25 00:50:02 +0000 to 2022-05-31 02:03:24 +0000 - Emit warning upon encountering multiple packages with the same name (rust-lang/cargo#10701) - Guide new users to add use `super::*;` to `mod test` (rust-lang/cargo#10706) - Document how to debug change detection events (rust-lang/cargo#10708) - fix(publish): add more check when use `publish -p <SPEC>` (rust-lang/cargo#10677) - fix key formatting when switching to a dotted `WorkspaceSource` (rust-lang/cargo#10705)
rust-lang/cargo#10706 switched the `cargo init --lib`-generated src/lib.rs to use a function and `use super::*;` inside the `mod test`. This makes it easier for new users to write their own functions and add tests, as it means the tests can refer to the new functions without any extra work, and without rustc asking them to add explicit `use`s for each new thing they add. This PR updates the parts of the book that use this src/lib.rs and similar examples, to match the new output of `cargo init --lib`, and to additionally help guide users to using `use super::*;` inside their `mod test`s. There is one non-example change, which is to update the wording in src/ch11-01-writing-tests.md to better reflect the new content in the associated example.
What does this PR try to resolve?
Currently,
cargo init --lib
produces examples for unit tests. However, new users will find that they are unable to use functions they defined above. This should resolve the confusion.Fixes #10559
How should we test and review this PR?
This PR does not create new features. Test this PR using the already-existing tests.
Additional information
I didn't think this was a major change, so I did not open a RFC for it. Please let me know if I should have!