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

Chapter 7.4 The part about "pub use" doesn't make isn't right #2766

Closed
rempas opened this issue Jun 22, 2021 · 2 comments
Closed

Chapter 7.4 The part about "pub use" doesn't make isn't right #2766

rempas opened this issue Jun 22, 2021 · 2 comments
Milestone

Comments

@rempas
Copy link

rempas commented Jun 22, 2021

I'm talking about this part. In the book it talks about how use is local to a scope and not to a module. I'm just learning Rust and I couldn't find how this applies so I made my research and found out about the reference book that talks about use visibility being local to a module and nowhere the word scope appears. The example in the book also doesn't make any sense while the example in the reference book makes absolute sense about how use applies to modules and how pub use is used to make the name publicly available to other modules.

Unless I'm doing something wrong of course, like I said I'm just learning Rust and I just wanted to report that.

@carols10cents carols10cents modified the milestones: ch 7, ch7 Jul 8, 2021
@limuyuan
Copy link
Contributor

limuyuan commented Aug 2, 2021

Strongly agree. I also find myself unable to understand what would happen if pub use is not used.

@carols10cents
Copy link
Member

"Scope" is the correct word to use rather than module, and I think the reference is actually imprecise in this case.

For example, this code doesn't compile because the use is local to the function's scope, not the whole module that both the const and the function are in:

const FOO: NonZeroI8 = NonZeroI8::new(5);

fn bar() {
    use std::num::NonZeroI8;
    
    let another = NonZeroI8::new(3);
}

For providing a better example of the effect pub use has, I think this issue is a duplicate of ##2716.

Thanks though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants