-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Comments
Would resolving #10573 by disallowing private things in public type signatures stop this from mattering? |
It would, but it's also unclear on what the resolution of #10573 should be I think. |
Oh, maybe pub use Foo = Bar;
struct Bar {
can_users_of_foo_see_this: int
} |
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 |
Accepted for P-backcompat-lang |
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.
…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
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
The text was updated successfully, but these errors were encountered: