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

Visibility modifiers on container members #569

Closed
scurest opened this issue Oct 29, 2017 · 3 comments
Closed

Visibility modifiers on container members #569

scurest opened this issue Oct 29, 2017 · 3 comments
Labels
question No questions on the issue tracker, please.
Milestone

Comments

@scurest
Copy link
Contributor

scurest commented Oct 29, 2017

Eg. these

struct {
    pub x: i32
    pub fn f() {}
    pub const v: i32 = 0;
}

which seem to do nothing (you can call private methods from anywhere AFAICT). Basically, I wanted to know if these are just unimplemented and what they're supposed to do.

  1. The stated grammar doesn't actually allow visibility modifiers on container members at all. Most of the docs use pub on struct methods though and the parser allows them in all the places above.
  2. If they were working, what's the intended unit of visibility? (I mean, where would you be allowed to access private members from?) The container, like in C++, or the file, like in Rust?
  3. The export modifier in particular seems pretty meaningless on fields.
@andrewrk
Copy link
Member

Good call, I need to address this.

(3) should be solved with #462

@andrewrk andrewrk added this to the 0.2.0 milestone Oct 29, 2017
@PavelVozenilek
Copy link

If possible, tests (but not examples) should be able to invoke private methods and access private members.

The usual advice for such situations is to restructure the code so that privates could be tested through public interface, or to extract private code out, but this leads to unneeded increase of complexity.

@andrewrk
Copy link
Member

For fields: pub will become invalid syntax with the accepted proposal #2059.

Functions are planned to become the same as variable declarations with #1717.

pub on a declaration means that it can be accessed from any scope. Without pub, declarations can be accessed from any scope in the same file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question No questions on the issue tracker, please.
Projects
None yet
Development

No branches or pull requests

3 participants