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

Fields of private structures should be private by default #11522

Closed
alexcrichton opened this issue Jan 14, 2014 · 5 comments
Closed

Fields of private structures should be private by default #11522

alexcrichton opened this issue Jan 14, 2014 · 5 comments
Labels
A-visibility Area: Visibility / privacy
Milestone

Comments

@alexcrichton
Copy link
Member

It was brought up recently that the rules for field privacy aren't quite as they were intended to be. Currently, fields are public by default, and you explicitly make them private. In the originally envisioned world, this was only true of pub structs. Private structs would have private-by-default.

This essentially means that the default visibility of fields inherits the visibility of the struct. I would also like to go so far as to disallow pub on fields of a private structure.

Nominating

@huonw
Copy link
Member

huonw commented Jan 14, 2014

Would resolving #10573 by disallowing private things in public type signatures stop this from mattering?

@alexcrichton
Copy link
Member Author

It would, but it's also unclear on what the resolution of #10573 should be I think.

@huonw
Copy link
Member

huonw commented Jan 14, 2014

Oh, maybe pub use would mean that this still needs to be handled explicitly.

pub use Foo = Bar;

struct Bar {
    can_users_of_foo_see_this: int
}

@alexcrichton
Copy link
Member Author

Good point! We have had a lot of bad luck in the past with inherited visibility, but technically this would bring structs in lines with enums, so maybe ok?

Sounds like we shouldn't deny pub field: type on a priv struct, but the fields should still be private by default.

@pnkfelix
Copy link
Member

Accepted for P-backcompat-lang

bors added a commit that referenced this issue Jan 26, 2014
See #11522, but the idea is for private structs to have private fields by default, whereas public structs will continue to have public fields by default.
flip1995 pushed a commit to flip1995/rust that referenced this issue Sep 25, 2023
…fate

[`redundant_guards`]: lint if the pattern is on the left side

A tiny improvement to the `redundant_guards` lint. There's no associated issue for this, just noticed it while going through the code.
Right now it warns on `Some(x) if x == 2` and suggests `Some(2)`, but it didn't do that for `Some(x) if 2 == x` (i.e. when the local is on the right side and the pattern on the left side).

changelog: [`redundant_guards`]: also lint if the pattern is on the left side
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-visibility Area: Visibility / privacy
Projects
None yet
Development

No branches or pull requests

3 participants