-
Notifications
You must be signed in to change notification settings - Fork 13.3k
pub use can reference private items in a an enclosing module #23266
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
Comments
triage: I-nominated (1.0 beta) back-compat issue |
Being able to access a parent's private items is an intentional part of the privacy system (you can access any private item in your ancestry). Although being able to reexport those private items may not necessarily be intended... |
Yeah, the title is not very clear, sorry, but it is the re-export part that I think is the bug, not the access. |
I think actually it is not as bad as I thought, in particular the third case is always Ok. Even if So that suggests that a fairly simple rule is that it should only be allowed to pub use an enclosing module's private items from a private module. |
Hmm, and now I'm not sure of the intended behaviour here. You can use |
Note that this issue is consistent with RFC 136 (i.e., under that RFC, the current implementation is wrong). |
cc me |
Note that currently you can
|
I think that per RFC 136 a pub use should require that the referenced items be public. |
(Whether or not they are in your module, a parent's module, etc) |
At least that was the intended semantics. |
Does that include the whole path? If so then that sounds wrong. Having to make every submodule you reexport an item from public makes it harder to hide the private interface. |
@mahkoh No, it means literally just that the item must be public |
I was thinking about cases with > 2 modules and I believe the rule that must hold is the same one I outline here. That is a In this case, there is also a simpler (and more conservative) model, which is that |
pub use should not be able to make a private item public, e.g., this is illegal:
However, if the private item is in an enclosing module then this is allowed. That is wrong (I think). However, it gets more complicated depending on if the enclosing module is itself public, because there is a useful pattern where the submodule
pub use
s an item in the enclosing module and that does not increase its visibility. Here are the possibilities:I'm not sure if we can check the third case easily (or at all). It might only be worth allowing the first case (this would break some code in the Rust repo and probably others though).
Note also that this interacts with the ban on private types in public items - this hole in visibility makes that work some times (I need to think more about that though)
The text was updated successfully, but these errors were encountered: