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

'use' declarations are private to the containing *scope*, not *module* #1187

Open
carols10cents opened this issue Mar 27, 2022 · 1 comment

Comments

@carols10cents
Copy link
Member

carols10cents commented Mar 27, 2022

This sentence says:

Like items, use declarations are private to the containing module, by default.

However, I think this should say:

Like items, use declarations are private to the containing scope, by default.

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

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

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

The usage of the word "module" here caused confusion in the book (which I'm also working on clarifying, but the filer assumed the reference would be more precise than the book and I don't think it is in this case): rust-lang/book#2766

This would also be a great place to link to the scopes section that this PR adds (and which I like a lot): #1040

@ehuss
Copy link
Contributor

ehuss commented Mar 27, 2022

Sounds reasonable to me. Also, #1052 rewrites most of the use chapter (to update it for 2018 path changes), though I didn't touch that visibility section.

Internally to rustc, blocks are called "anonymous modules". I don't know if the original author was using this terminology. So in that way it makes sense. However, I agree that is a bit obscure and potentially confusing to most users.

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

2 participants