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

Add use super::*; to unit-test examples. #3188

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

sunfishcode
Copy link
Member

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 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 to
additionally help guide users to using use super::*; inside their
mod 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.

@carols10cents carols10cents added this to the ch11 milestone Jun 1, 2022
@carols10cents
Copy link
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!

@carols10cents carols10cents added the blocked upstream Blocked on a change that needs to happen in a different repo first label Jun 4, 2022
@mweber15
Copy link

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.
@sunfishcode
Copy link
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!

@chriskrycho
Copy link
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!

@chriskrycho chriskrycho merged commit fcfac81 into rust-lang:main Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked upstream Blocked on a change that needs to happen in a different repo first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants