rust-lang / book

The Rust Programming Language

Home Page:https://doc.rust-lang.org/book/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ambiguous sentence

0xalizk opened this issue · comments

URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html#paths-for-referring-to-an-item-in-the-module-tree

Description of the problem:

The 2nd sentence here is incoherent: "In Rust, all items (functions, methods, structs, enums, modules, and constants) are private to parent modules by default. If you want to make an item like a function or struct private, you put it in a module."

Suggested fix:

  • Remove the second sentence "If you want to make an item like a function or struct private, you put it in a module."

  • Reasoning: visibility is determined by (a) pub or lack thereof in both item and module definition and (b) as location of item within the module tree. So this sentence is too reductive.

Can I please work on this?

Can you please assign this issue to me?

I don’t think the sentence here is incoherent, and this is not quite right either:

visibility is determined by (a) pub or lack thereof in both item and module definition and (b) as location of item within the module tree.

In context (the context you quoted, in fact!), the other qualifications about visibility are already stated. And to be extra clear:

  1. The only way you can make something private in Rust is by putting it in a module.
  2. Things in modules are private by default, not public by default, so putting something in a module and not adding a pub, pub(super), pub(crate), etc. keyword on it does in fact make it private.

Given that, I am going to go ahead and close this and we will leave the text as is, though I will keep it in mind as we consider whether to make any changes to the book materials on crates and modules for the 2024 revision. Thanks!