Skip to content

Documenting and fixing resolve's notion of public/private #8215

Closed

Description

Making an issue off of my email to the mailing list.

Currently today resolve is generally considered "broken", and I think that this would benefit from actually writing the rules down, writing lots of test cases and documentation, and then fixing resolve. To the best of my knowledge, these are the rules which resolve should follow for determining whether an item is public or private and whether a certain path should resolve or not:

  1. All items are private by default, with the exception of struct fields.
    To flag an item as public, you use pub. Also pub is not allowed on impl
    or extern (visibility is determined by each item individually).
  2. For a path which is a cross-crate reference, it is only valid of every
    item in the path is marked as pub.
  3. A module may access any item from its immediate parent.
  4. A module may access any item from its immediate children.
  5. Any local-crate path which goes outside the bounds of 3/4 will only resolve
    if each component of the path is pub. For example I could reach into a
    child's private mod's pub items, but not the child's private mod's non-pub
    items.

I'm nominating for a backwards-compatibility milestone as there's probably lots of existing code which is doing the wrong thing by accident.

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions