Add use super::*; to unit-test examples.#3188
Merged
chriskrycho merged 1 commit intorust-lang:mainfrom Dec 9, 2024
Merged
Conversation
Member
|
It looks like this change will be in Rust 1.63; I am not seeing this behavior with stable 1.61.0 or 1.62.0-beta.3. I'll merge this when the change has been stabilized! |
|
I was about to work on a PR for this, but fortunately I found this one first. I'm working through the book with Rust 1.64 and this PR appears to resolve the differences between the book and the generated code. Hopefully this can be merged soon. |
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.
Member
Author
|
The changes this is documenting are now in stable Rust, and I've now resolved the merge conflicts, so unless there are any other concerns, this should be ready to go! |
Contributor
|
@sunfishcode feel like doing one more pass of conflict resolutions? If not, I will get to it later this week or early next. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rust-lang/cargo#10706 switched the
cargo init --lib-generated src/lib.rsto use a function and
use super::*;inside themod test. This makesit 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
uses 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 toadditionally help guide users to using
use super::*;inside theirmod tests.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.