-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Private struct fields by default #13184
Conversation
Regarding your "Changes yet to be done", the RFC as written does not make any changes to enums. Removing |
Ah, sorry about that, I meant to send a separate RFC for that, and I forgot I didn't! |
This commit switches privacy's checking of fields to have *all* fields be private by default. This does not yet change tuple structs, this only affects structs with named fields. The fallout of this change will follow shortly. RFC: 0004-private-fields cc rust-lang#8122 Closes rust-lang#11809
This is an implementation of a portion of [RFC #4](https://github.com/rust-lang/rfcs/blob/master/active/0004-private-fields.md). This PR makes named struct fields private by default (as opposed to inherited by default). The only real meaty change is the first commit to `rustc`, all other commits are just fallout of that change. Summary of changes made: * Named fields are private by default *everywhere* * The `priv` keyword is now default-deny on named fields (done in a "lint" pass in privacy) Changes yet to be done (before the RFC is closed) * Change tuple structs to have private fields by default * Remove `priv` enum variants * Make `priv` a reserved keyword
This is a continuation of the work done in rust-lang#13184 to make struct fields private by default. This commit finishes RFC 4 by making all tuple structs have private fields by default. Note that enum variants are not affected. A tuple struct having a private field means that it cannot be matched on in a pattern match (both refutable and irrefutable), and it also cannot have a value specified to be constructed. Similarly to private fields, switching the type of a private field in a tuple struct should be able to be done in a backwards compatible way. The one snag that I ran into which wasn't mentioned in the RFC is that this commit also forbids taking the value of a tuple struct constructor. For example, this code now fails to compile: mod a { pub struct A(int); } let a: fn(int) -> a::A = a::A; //~ ERROR: first field is private Although no fields are bound in this example, it exposes implementation details through the type itself. For this reason, taking the value of a struct constructor with private fields is forbidden (outside the containing module). RFC: 0004-private-fields
If I am not mistaken, you missed the time module. Currently I cannot get the sec field from a Timespec struct. |
Ah great, thanks! |
The calculation for whether a field is public or private was tweaked in rust-lang#13184, but I forgot to update rustdoc. Closes rust-lang#13310
Filter imports on find-all-references Attempt to rust-lang#13184
fix false positive in explicit_iter_loop with msrv close rust-lang#13184 This PR fix false positive in explicit_iter_loop when msrv < 1.80 changelog: fix false positive in explicit_iter_loop when msrv < 1.80
This is an implementation of a portion of RFC #4. This PR makes named struct fields private by default (as opposed to inherited by default).
The only real meaty change is the first commit to
rustc
, all other commits are just fallout of that change.Summary of changes made:
priv
keyword is now default-deny on named fields (done in a "lint" pass in privacy)Changes yet to be done (before the RFC is closed)
priv
enum variantspriv
a reserved keyword