From bf6c1429ea3d407b2a9d4f9af5a31f8fa4d731bc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 10 Mar 2014 15:06:02 -0700 Subject: [PATCH 1/2] RFC: Remove the `priv` keyword --- active/0000-remove-priv.md | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 active/0000-remove-priv.md diff --git a/active/0000-remove-priv.md b/active/0000-remove-priv.md new file mode 100644 index 00000000000..ff89347d282 --- /dev/null +++ b/active/0000-remove-priv.md @@ -0,0 +1,82 @@ +- Start Date: 2014-03-31 +- RFC PR #: (leave this empty) +- Rust Issue #: (leave this empty) + +# Summary + +This RFC is a proposal to remove the usage of the keyword `priv` from the Rust +language. + +# Motivation + +By removing `priv` entirely from the language, it significantly simplifies the +privacy semantics as well as the ability to explain it to newcomers. The one +remaining case, private enum variants, can be rewritten as such: + +```rust +// pub enum Foo { +// Bar, +// priv Baz, +// } + +enum Foo { + Bar, + Baz(BazInner) +} + +pub struct BazInner(()); + +// pub enum Foo2 { +// priv Bar2, +// priv Baz2, +// } + +pub struct Foo2 { + variant: FooVariant +} + +enum FooVariant { + Bar2, + Baz2, +} +``` + +Private enum variants are a rarely used feature of the language, and are +generally not regarded as a strong enough feature to justify the `priv` keyword +entirely. + +# Detailed design + +There remains only one use case of the `priv` visibility qualifier in the Rust +language, which is to make enum variants private. For example, it is possible +today to write a type such as: + +```rust +pub enum Foo { + Bar, + priv Baz +} +``` + +In this example, the variant `Bar` is public, while the variant `Baz` is +private. This RFC would remove this ability to have private enum variants. + +In addition to disallowing the `priv` keyword on enum variants, this RFC would +also forbid visibility qualifiers in front of enum variants entirely, as they no +longer serve any purpose. + +### Status of the identifier `priv` + +This RFC would demote the identifier `priv` from being a keyword to being a +reserved keyword (in case we find a use for it in the future). + +# Alternatives + +* Allow private enum variants, as-is today. +* Add a new keyword for `enum` which means "my variants are all private" with + controls to make variants public. + +# Unresolved questions + +* Is the assertion that private enum variants are rarely used true? Are there + legitimate use cases for keeping the `priv` keyword? From 8c4aedc8369576fb0447b67627848b54dea9a73c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 8 Apr 2014 08:30:53 -0700 Subject: [PATCH 2/2] Correct the example code --- active/0000-remove-priv.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active/0000-remove-priv.md b/active/0000-remove-priv.md index ff89347d282..13b2b3ce6c5 100644 --- a/active/0000-remove-priv.md +++ b/active/0000-remove-priv.md @@ -19,7 +19,7 @@ remaining case, private enum variants, can be rewritten as such: // priv Baz, // } -enum Foo { +pub enum Foo { Bar, Baz(BazInner) }