From 83351fa02e08caa8fb8017254cc6e7c99fc65d2b Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Tue, 15 Apr 2014 18:05:38 -0700
Subject: [PATCH 1/3] Remove usage of private enum variants

This replaces all uses of private enum variants with a struct that has
one private field pointing at a private enum.

RFC: 0006-remove-priv
---
 src/liblibc/lib.rs                     |  4 +-
 src/librand/distributions/gamma.rs     | 36 ++++++++++------
 src/librustc/middle/trans/debuginfo.rs | 30 +++++++------
 src/libsyntax/util/small_vector.rs     | 59 +++++++++++++++-----------
 4 files changed, 76 insertions(+), 53 deletions(-)

diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs
index 18e815e9b7c03..379d3cdc94e4f 100644
--- a/src/liblibc/lib.rs
+++ b/src/liblibc/lib.rs
@@ -229,8 +229,8 @@ pub mod types {
             */
             #[repr(u8)]
             pub enum c_void {
-                priv variant1,
-                priv variant2
+                __variant1,
+                __variant2,
             }
             pub enum FILE {}
             pub enum fpos_t {}
diff --git a/src/librand/distributions/gamma.rs b/src/librand/distributions/gamma.rs
index 6ec8411495a53..dd249a1fbcac8 100644
--- a/src/librand/distributions/gamma.rs
+++ b/src/librand/distributions/gamma.rs
@@ -45,10 +45,14 @@ use super::{IndependentSample, Sample, Exp};
 /// for Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3
 /// (September 2000),
 /// 363-372. DOI:[10.1145/358407.358414](http://doi.acm.org/10.1145/358407.358414)
-pub enum Gamma {
-    priv Large(GammaLargeShape),
-    priv One(Exp),
-    priv Small(GammaSmallShape)
+pub struct Gamma {
+    repr: GammaRepr,
+}
+
+enum GammaRepr {
+    Large(GammaLargeShape),
+    One(Exp),
+    Small(GammaSmallShape)
 }
 
 // These two helpers could be made public, but saving the
@@ -90,11 +94,12 @@ impl Gamma {
         assert!(shape > 0.0, "Gamma::new called with shape <= 0");
         assert!(scale > 0.0, "Gamma::new called with scale <= 0");
 
-        match shape {
+        let repr = match shape {
             1.0        => One(Exp::new(1.0 / scale)),
             0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
             _          => Large(GammaLargeShape::new_raw(shape, scale))
-        }
+        };
+        Gamma { repr: repr }
     }
 }
 
@@ -131,7 +136,7 @@ impl Sample<f64> for GammaLargeShape {
 
 impl IndependentSample<f64> for Gamma {
     fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
-        match *self {
+        match self.repr {
             Small(ref g) => g.ind_sample(rng),
             One(ref g) => g.ind_sample(rng),
             Large(ref g) => g.ind_sample(rng),
@@ -183,24 +188,29 @@ impl IndependentSample<f64> for GammaLargeShape {
 /// let v = chi.ind_sample(&mut rand::task_rng());
 /// println!("{} is from a χ²(11) distribution", v)
 /// ```
-pub enum ChiSquared {
+pub struct ChiSquared {
+    repr: ChiSquaredRepr,
+}
+
+enum ChiSquaredRepr {
     // k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1,
     // e.g. when alpha = 1/2 as it would be for this case, so special-
     // casing and using the definition of N(0,1)^2 is faster.
-    priv DoFExactlyOne,
-    priv DoFAnythingElse(Gamma)
+    DoFExactlyOne,
+    DoFAnythingElse(Gamma),
 }
 
 impl ChiSquared {
     /// Create a new chi-squared distribution with degrees-of-freedom
     /// `k`. Fails if `k < 0`.
     pub fn new(k: f64) -> ChiSquared {
-        if k == 1.0 {
+        let repr = if k == 1.0 {
             DoFExactlyOne
         } else {
             assert!(k > 0.0, "ChiSquared::new called with `k` < 0");
             DoFAnythingElse(Gamma::new(0.5 * k, 2.0))
-        }
+        };
+        ChiSquared { repr: repr }
     }
 }
 impl Sample<f64> for ChiSquared {
@@ -208,7 +218,7 @@ impl Sample<f64> for ChiSquared {
 }
 impl IndependentSample<f64> for ChiSquared {
     fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
-        match *self {
+        match self.repr {
             DoFExactlyOne => {
                 // k == 1 => N(0,1)^2
                 let StandardNormal(norm) = rng.gen::<StandardNormal>();
diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs
index ae58e153258ef..0514642c58390 100644
--- a/src/librustc/middle/trans/debuginfo.rs
+++ b/src/librustc/middle/trans/debuginfo.rs
@@ -206,15 +206,19 @@ impl CrateDebugContext {
     }
 }
 
-pub enum FunctionDebugContext {
-    priv FunctionDebugContext(~FunctionDebugContextData),
-    priv DebugInfoDisabled,
-    priv FunctionWithoutDebugInfo,
+pub struct FunctionDebugContext {
+    repr: FunctionDebugContextRepr,
+}
+
+enum FunctionDebugContextRepr {
+    FunctionDebugContext(~FunctionDebugContextData),
+    DebugInfoDisabled,
+    FunctionWithoutDebugInfo,
 }
 
 impl FunctionDebugContext {
     fn get_ref<'a>(&'a self, cx: &CrateContext, span: Span) -> &'a FunctionDebugContextData {
-        match *self {
+        match self.repr {
             FunctionDebugContext(~ref data) => data,
             DebugInfoDisabled => {
                 cx.sess().span_bug(span, FunctionDebugContext::debuginfo_disabled_message());
@@ -544,7 +548,7 @@ pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) {
 pub fn set_source_location(fcx: &FunctionContext,
                            node_id: ast::NodeId,
                            span: Span) {
-    match fcx.debug_context {
+    match fcx.debug_context.repr {
         DebugInfoDisabled => return,
         FunctionWithoutDebugInfo => {
             set_debug_location(fcx.ccx, UnknownLocation);
@@ -585,7 +589,7 @@ pub fn clear_source_location(fcx: &FunctionContext) {
 /// and must therefore be called before the first real statement/expression of the function is
 /// translated.
 pub fn start_emitting_source_locations(fcx: &FunctionContext) {
-    match fcx.debug_context {
+    match fcx.debug_context.repr {
         FunctionDebugContext(~ref data) => {
             data.source_locations_enabled.set(true)
         },
@@ -603,7 +607,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
                                      param_substs: Option<@param_substs>,
                                      llfn: ValueRef) -> FunctionDebugContext {
     if cx.sess().opts.debuginfo == NoDebugInfo {
-        return DebugInfoDisabled;
+        return FunctionDebugContext { repr: DebugInfoDisabled };
     }
 
     // Clear the debug location so we don't assign them in the function prelude. Do this here
@@ -611,7 +615,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
     set_debug_location(cx, UnknownLocation);
 
     if fn_ast_id == -1 {
-        return FunctionWithoutDebugInfo;
+        return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
     }
 
     let empty_generics = ast::Generics { lifetimes: Vec::new(), ty_params: OwnedSlice::empty() };
@@ -678,7 +682,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
         ast_map::NodeForeignItem(..) |
         ast_map::NodeVariant(..) |
         ast_map::NodeStructCtor(..) => {
-            return FunctionWithoutDebugInfo;
+            return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
         }
         _ => cx.sess().bug(format!("create_function_debug_context: \
                                     unexpected sort of node: {:?}", fnitem))
@@ -686,7 +690,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
 
     // This can be the case for functions inlined from another crate
     if span == codemap::DUMMY_SP {
-        return FunctionWithoutDebugInfo;
+        return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
     }
 
     let loc = span_start(cx, span);
@@ -761,7 +765,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
                        fn_metadata,
                        &mut *fn_debug_context.scope_map.borrow_mut());
 
-    return FunctionDebugContext(fn_debug_context);
+    return FunctionDebugContext { repr: FunctionDebugContext(fn_debug_context) };
 
     fn get_function_signature(cx: &CrateContext,
                               fn_ast_id: ast::NodeId,
@@ -2335,7 +2339,7 @@ fn DIB(cx: &CrateContext) -> DIBuilderRef {
 }
 
 fn fn_should_be_ignored(fcx: &FunctionContext) -> bool {
-    match fcx.debug_context {
+    match fcx.debug_context.repr {
         FunctionDebugContext(_) => false,
         _ => true
     }
diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs
index 1dcebd7a01617..792673e329817 100644
--- a/src/libsyntax/util/small_vector.rs
+++ b/src/libsyntax/util/small_vector.rs
@@ -12,15 +12,19 @@ use std::mem;
 use std::vec;
 
 /// A vector type optimized for cases where the size is almost always 0 or 1
-pub enum SmallVector<T> {
-    priv Zero,
-    priv One(T),
-    priv Many(Vec<T> ),
+pub struct SmallVector<T> {
+    repr: SmallVectorRepr<T>,
+}
+
+enum SmallVectorRepr<T> {
+    Zero,
+    One(T),
+    Many(Vec<T> ),
 }
 
 impl<T> Container for SmallVector<T> {
     fn len(&self) -> uint {
-        match *self {
+        match self.repr {
             Zero => 0,
             One(..) => 1,
             Many(ref vals) => vals.len()
@@ -30,7 +34,7 @@ impl<T> Container for SmallVector<T> {
 
 impl<T> FromIterator<T> for SmallVector<T> {
     fn from_iter<I: Iterator<T>>(iter: I) -> SmallVector<T> {
-        let mut v = Zero;
+        let mut v = SmallVector::zero();
         v.extend(iter);
         v
     }
@@ -46,24 +50,24 @@ impl<T> Extendable<T> for SmallVector<T> {
 
 impl<T> SmallVector<T> {
     pub fn zero() -> SmallVector<T> {
-        Zero
+        SmallVector { repr: Zero }
     }
 
     pub fn one(v: T) -> SmallVector<T> {
-        One(v)
+        SmallVector { repr: One(v) }
     }
 
-    pub fn many(vs: Vec<T> ) -> SmallVector<T> {
-        Many(vs)
+    pub fn many(vs: Vec<T>) -> SmallVector<T> {
+        SmallVector { repr: Many(vs) }
     }
 
     pub fn push(&mut self, v: T) {
-        match *self {
-            Zero => *self = One(v),
+        match self.repr {
+            Zero => self.repr = One(v),
             One(..) => {
-                let one = mem::replace(self, Zero);
+                let one = mem::replace(&mut self.repr, Zero);
                 match one {
-                    One(v1) => mem::replace(self, Many(vec!(v1, v))),
+                    One(v1) => mem::replace(&mut self.repr, Many(vec!(v1, v))),
                     _ => unreachable!()
                 };
             }
@@ -78,7 +82,7 @@ impl<T> SmallVector<T> {
     }
 
     pub fn get<'a>(&'a self, idx: uint) -> &'a T {
-        match *self {
+        match self.repr {
             One(ref v) if idx == 0 => v,
             Many(ref vs) => vs.get(idx),
             _ => fail!("out of bounds access")
@@ -86,7 +90,7 @@ impl<T> SmallVector<T> {
     }
 
     pub fn expect_one(self, err: &'static str) -> T {
-        match self {
+        match self.repr {
             One(v) => v,
             Many(v) => {
                 if v.len() == 1 {
@@ -100,27 +104,32 @@ impl<T> SmallVector<T> {
     }
 
     pub fn move_iter(self) -> MoveItems<T> {
-        match self {
+        let repr = match self.repr {
             Zero => ZeroIterator,
             One(v) => OneIterator(v),
             Many(vs) => ManyIterator(vs.move_iter())
-        }
+        };
+        MoveItems { repr: repr }
     }
 }
 
-pub enum MoveItems<T> {
-    priv ZeroIterator,
-    priv OneIterator(T),
-    priv ManyIterator(vec::MoveItems<T>),
+pub struct MoveItems<T> {
+    repr: MoveItemsRepr<T>,
+}
+
+enum MoveItemsRepr<T> {
+    ZeroIterator,
+    OneIterator(T),
+    ManyIterator(vec::MoveItems<T>),
 }
 
 impl<T> Iterator<T> for MoveItems<T> {
     fn next(&mut self) -> Option<T> {
-        match *self {
+        match self.repr {
             ZeroIterator => None,
             OneIterator(..) => {
                 let mut replacement = ZeroIterator;
-                mem::swap(self, &mut replacement);
+                mem::swap(&mut self.repr, &mut replacement);
                 match replacement {
                     OneIterator(v) => Some(v),
                     _ => unreachable!()
@@ -131,7 +140,7 @@ impl<T> Iterator<T> for MoveItems<T> {
     }
 
     fn size_hint(&self) -> (uint, Option<uint>) {
-        match *self {
+        match self.repr {
             ZeroIterator => (0, Some(0)),
             OneIterator(..) => (1, Some(1)),
             ManyIterator(ref inner) => inner.size_hint()

From 5cfbc0e7aeefd30611213da33307723bcb490ac6 Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Tue, 15 Apr 2014 18:02:58 -0700
Subject: [PATCH 2/3] rustc: Remove private enum variants

This removes the `priv` keyword from the language and removes private enum
variants as a result. The remaining use cases of private enum variants were all
updated to be a struct with one private field that is a private enum.

RFC: 0006-remove-priv

Closes #13535
---
 src/doc/rust.md                               |  4 +-
 src/librustc/metadata/decoder.rs              |  8 +-
 src/librustc/metadata/encoder.rs              |  2 -
 src/librustc/middle/privacy.rs                | 80 +++----------------
 src/librustc/middle/resolve.rs                | 11 +--
 src/librustdoc/doctree.rs                     |  2 +-
 src/librustdoc/html/format.rs                 |  1 -
 src/libsyntax/ast.rs                          |  3 +-
 src/libsyntax/parse/parser.rs                 |  7 +-
 src/libsyntax/print/pprust.rs                 |  2 -
 src/test/auxiliary/private_variant_xc.rs      | 14 ----
 ...te_variant_1.rs => unreachable-variant.rs} |  2 +-
 src/test/compile-fail/assign-to-method.rs     |  2 +-
 src/test/compile-fail/class-cast-to-trait.rs  |  2 +-
 src/test/compile-fail/class-missing-self.rs   |  2 +-
 src/test/compile-fail/issue-3993-2.rs         |  4 +-
 src/test/compile-fail/issue-9957.rs           |  3 -
 src/test/compile-fail/lint-missing-doc.rs     |  4 -
 .../lint-visible-private-types.rs             |  5 --
 src/test/compile-fail/privacy1.rs             |  3 -
 src/test/compile-fail/private-method.rs       |  2 +-
 src/test/compile-fail/private-variant-xc.rs   | 18 -----
 src/test/compile-fail/private-variant.rs      | 21 -----
 .../compile-fail/removed-syntax-priv-group.rs | 17 ----
 src/test/compile-fail/unnecessary-private.rs  |  2 +-
 ...te_variant_2.rs => unreachable-variant.rs} |  6 +-
 src/test/compile-fail/useless-priv.rs         |  2 -
 27 files changed, 31 insertions(+), 198 deletions(-)
 delete mode 100644 src/test/auxiliary/private_variant_xc.rs
 rename src/test/auxiliary/{private_variant_1.rs => unreachable-variant.rs} (95%)
 delete mode 100644 src/test/compile-fail/private-variant-xc.rs
 delete mode 100644 src/test/compile-fail/private-variant.rs
 delete mode 100644 src/test/compile-fail/removed-syntax-priv-group.rs
 rename src/test/compile-fail/{private_variant_2.rs => unreachable-variant.rs} (77%)

diff --git a/src/doc/rust.md b/src/doc/rust.md
index f2df445a5a276..778c1ce026816 100644
--- a/src/doc/rust.md
+++ b/src/doc/rust.md
@@ -1586,10 +1586,10 @@ pub struct Bar {
     field: int
 }
 
-// Declare a public enum with public and private variants
+// Declare a public enum with two public variants
 pub enum State {
     PubliclyAccessibleState,
-    priv PrivatelyAccessibleState
+    PubliclyAccessibleState2,
 }
 ~~~~
 
diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs
index 5fe59a787737a..ee7ce817a3f20 100644
--- a/src/librustc/metadata/decoder.rs
+++ b/src/librustc/metadata/decoder.rs
@@ -124,7 +124,6 @@ enum Family {
     Trait,                 // I
     Struct,                // S
     PublicField,           // g
-    PrivateField,          // j
     InheritedField         // N
 }
 
@@ -149,7 +148,6 @@ fn item_family(item: ebml::Doc) -> Family {
       'I' => Trait,
       'S' => Struct,
       'g' => PublicField,
-      'j' => PrivateField,
       'N' => InheritedField,
        c => fail!("unexpected family char: {}", c)
     }
@@ -161,7 +159,6 @@ fn item_visibility(item: ebml::Doc) -> ast::Visibility {
         Some(visibility_doc) => {
             match reader::doc_as_u8(visibility_doc) as char {
                 'y' => ast::Public,
-                'n' => ast::Private,
                 'i' => ast::Inherited,
                 _ => fail!("unknown visibility character")
             }
@@ -364,7 +361,7 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
         Trait => DlDef(ast::DefTrait(did)),
         Enum => DlDef(ast::DefTy(did)),
         Impl => DlImpl(did),
-        PublicField | PrivateField | InheritedField => DlField,
+        PublicField | InheritedField => DlField,
     }
 }
 
@@ -962,7 +959,6 @@ pub fn get_item_attrs(cdata: Cmd,
 fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
     match family {
       PublicField => ast::Public,
-      PrivateField => ast::Private,
       InheritedField => ast::Inherited,
       _ => fail!()
     }
@@ -975,7 +971,7 @@ pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
     let mut result = Vec::new();
     reader::tagged_docs(item, tag_item_field, |an_item| {
         let f = item_family(an_item);
-        if f == PublicField || f == PrivateField || f == InheritedField {
+        if f == PublicField || f == InheritedField {
             // FIXME #6993: name should be of type Name, not Ident
             let name = item_name(&*intr, an_item);
             let did = item_def_id(an_item, cdata);
diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs
index d5313eb257810..085a96ea7be2f 100644
--- a/src/librustc/metadata/encoder.rs
+++ b/src/librustc/metadata/encoder.rs
@@ -607,7 +607,6 @@ fn encode_struct_field_family(ebml_w: &mut Encoder,
                               visibility: Visibility) {
     encode_family(ebml_w, match visibility {
         Public => 'g',
-        Private => 'j',
         Inherited => 'N'
     });
 }
@@ -616,7 +615,6 @@ fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) {
     ebml_w.start_tag(tag_items_data_item_visibility);
     let ch = match visibility {
         Public => 'y',
-        Private => 'n',
         Inherited => 'i',
     };
     ebml_w.wr_str(str::from_char(ch));
diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs
index ee514ba5f2438..798fc2ffa33c0 100644
--- a/src/librustc/middle/privacy.rs
+++ b/src/librustc/middle/privacy.rs
@@ -67,18 +67,10 @@ impl Visitor<()> for ParentVisitor {
             // they inherit privacy
             ast::ItemEnum(ref def, _) => {
                 for variant in def.variants.iter() {
-                    // If variants are private, then their logical "parent" is
-                    // the enclosing module because everyone in the enclosing
-                    // module can still use the private variant
-                    if variant.node.vis == ast::Private {
-                        self.parents.insert(variant.node.id, self.curparent);
-
-                    // Otherwise, if the variant is public, then the parent is
-                    // considered the enclosing enum because the enum will
-                    // dictate the privacy visibility of this variant instead.
-                    } else {
-                        self.parents.insert(variant.node.id, item.id);
-                    }
+                    // The parent is considered the enclosing enum because the
+                    // enum will dictate the privacy visibility of this variant
+                    // instead.
+                    self.parents.insert(variant.node.id, item.id);
                 }
             }
 
@@ -224,9 +216,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
             // public all variants are public unless they're explicitly priv
             ast::ItemEnum(ref def, _) if public_first => {
                 for variant in def.variants.iter() {
-                    if variant.node.vis != ast::Private {
-                        self.exported_items.insert(variant.node.id);
-                    }
+                    self.exported_items.insert(variant.node.id);
                 }
             }
 
@@ -462,10 +452,7 @@ impl<'a> PrivacyVisitor<'a> {
                 Some(ast_map::NodeForeignItem(_)) => {
                     self.tcx.map.get_foreign_vis(closest_private_id)
                 }
-                Some(ast_map::NodeVariant(ref v)) => {
-                    // sadly enum variants still inherit visibility, so only
-                    // break out of this is explicitly private
-                    if v.node.vis == ast::Private { break }
+                Some(ast_map::NodeVariant(..)) => {
                     ast::Public // need to move up a level (to the enum)
                 }
                 _ => ast::Public,
@@ -997,10 +984,6 @@ impl<'a> Visitor<()> for SanePrivacyVisitor<'a> {
     fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
         match i.vis {
             ast::Inherited => {}
-            ast::Private => {
-                self.tcx.sess.span_err(i.span, "unnecessary visibility \
-                                                qualifier");
-            }
             ast::Public => {
                 if self.in_fn {
                     self.tcx.sess.span_err(i.span, "unnecessary `pub`, imports \
@@ -1036,25 +1019,6 @@ impl<'a> SanePrivacyVisitor<'a> {
                 }
             }
         };
-        let check_not_priv = |sp: Span, vis: ast::Visibility, note: &str| {
-            if vis == ast::Private {
-                tcx.sess.span_err(sp, "unnecessary `priv` qualifier");
-                if note.len() > 0 {
-                    tcx.sess.span_note(sp, note);
-                }
-            }
-        };
-        let check_struct = |def: &@ast::StructDef| {
-            for f in def.fields.iter() {
-                match f.node.kind {
-                    ast::NamedField(_, ast::Private) => {
-                        tcx.sess.span_err(f.span, "unnecessary `priv` \
-                                                   visibility");
-                    }
-                    ast::NamedField(..) | ast::UnnamedField(..) => {}
-                }
-            }
-        };
         match item.node {
             // implementations of traits don't need visibility qualifiers because
             // that's controlled by having the trait in scope.
@@ -1067,22 +1031,14 @@ impl<'a> SanePrivacyVisitor<'a> {
                 }
             }
 
-            ast::ItemImpl(_, _, _, ref methods) => {
+            ast::ItemImpl(..) => {
                 check_inherited(item.span, item.vis,
                                 "place qualifiers on individual methods instead");
-                for i in methods.iter() {
-                    check_not_priv(i.span, i.vis, "functions are private by \
-                                                   default");
-                }
             }
-            ast::ItemForeignMod(ref fm) => {
+            ast::ItemForeignMod(..) => {
                 check_inherited(item.span, item.vis,
                                 "place qualifiers on individual functions \
                                  instead");
-                for i in fm.items.iter() {
-                    check_not_priv(i.span, i.vis, "functions are private by \
-                                                   default");
-                }
             }
 
             ast::ItemEnum(ref def, _) => {
@@ -1094,24 +1050,11 @@ impl<'a> SanePrivacyVisitor<'a> {
                                                            visibility");
                             }
                         }
-                        ast::Private => {
-                            if item.vis != ast::Public {
-                                tcx.sess.span_err(v.span, "unnecessary `priv` \
-                                                           visibility");
-                            }
-                        }
                         ast::Inherited => {}
                     }
-
-                    match v.node.kind {
-                        ast::StructVariantKind(ref s) => check_struct(s),
-                        ast::TupleVariantKind(..) => {}
-                    }
                 }
             }
 
-            ast::ItemStruct(ref def, _) => check_struct(def),
-
             ast::ItemTrait(_, _, ref methods) => {
                 for m in methods.iter() {
                     match *m {
@@ -1124,12 +1067,9 @@ impl<'a> SanePrivacyVisitor<'a> {
                 }
             }
 
-            ast::ItemStatic(..) |
+            ast::ItemStatic(..) | ast::ItemStruct(..) |
             ast::ItemFn(..) | ast::ItemMod(..) | ast::ItemTy(..) |
-            ast::ItemMac(..) => {
-                check_not_priv(item.span, item.vis, "items are private by \
-                                                     default");
-            }
+            ast::ItemMac(..) => {}
         }
     }
 
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index e5b13adb4d0dc..9c00b8adfa331 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -1421,12 +1421,8 @@ impl<'a> Resolver<'a> {
                                        variant: &Variant,
                                        item_id: DefId,
                                        parent: ReducedGraphParent,
-                                       parent_public: bool) {
+                                       is_public: bool) {
         let ident = variant.node.name;
-        // FIXME: this is unfortunate to have to do this privacy calculation
-        //      here. This should be living in middle::privacy, but it's
-        //      necessary to keep around in some form becaues of glob imports...
-        let is_public = parent_public && variant.node.vis != ast::Private;
 
         match variant.node.kind {
             TupleVariantKind(_) => {
@@ -1668,12 +1664,11 @@ impl<'a> Resolver<'a> {
             // We assume the parent is visible, or else we wouldn't have seen
             // it. Also variants are public-by-default if the parent was also
             // public.
-            let is_public = vis != ast::Private;
             if is_struct {
-                child_name_bindings.define_type(def, DUMMY_SP, is_public);
+                child_name_bindings.define_type(def, DUMMY_SP, true);
                 self.structs.insert(variant_id);
             } else {
-                child_name_bindings.define_value(def, DUMMY_SP, is_public);
+                child_name_bindings.define_value(def, DUMMY_SP, true);
             }
           }
           DefFn(..) | DefStaticMethod(..) | DefStatic(..) => {
diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs
index 5104ce81465ba..1de53ecc68f3a 100644
--- a/src/librustdoc/doctree.rs
+++ b/src/librustdoc/doctree.rs
@@ -41,7 +41,7 @@ impl Module {
         Module {
             name       : name,
             id: 0,
-            vis: ast::Private,
+            vis: ast::Inherited,
             where: syntax::codemap::DUMMY_SP,
             attrs      : Vec::new(),
             structs    : Vec::new(),
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index ca55d1f04ad2f..cf989f7201139 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -507,7 +507,6 @@ impl fmt::Show for VisSpace {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self.get() {
             Some(ast::Public) => write!(f.buf, "pub "),
-            Some(ast::Private) => write!(f.buf, "priv "),
             Some(ast::Inherited) | None => Ok(())
         }
     }
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 1674902fb9659..33c0f2c46bb5e 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1038,7 +1038,6 @@ pub struct TraitRef {
 #[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
 pub enum Visibility {
     Public,
-    Private,
     Inherited,
 }
 
@@ -1046,7 +1045,7 @@ impl Visibility {
     pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
         match self {
             &Inherited => parent_visibility,
-            &Public | &Private => *self
+            &Public => *self
         }
     }
 }
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 88480c1b336a4..634e1c77c6af3 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -39,7 +39,7 @@ use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal}
 use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability};
 use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum};
 use ast::{PatIdent, PatLit, PatRange, PatRegion, PatStruct};
-use ast::{PatTup, PatUniq, PatWild, PatWildMulti, Private};
+use ast::{PatTup, PatUniq, PatWild, PatWildMulti};
 use ast::{BiRem, Required};
 use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl};
 use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
@@ -3953,10 +3953,6 @@ impl<'a> Parser<'a> {
 
         let attrs = self.parse_outer_attributes();
 
-        if self.eat_keyword(keywords::Priv) {
-            return self.parse_single_struct_field(Private, attrs);
-        }
-
         if self.eat_keyword(keywords::Pub) {
            return self.parse_single_struct_field(Public, attrs);
         }
@@ -3967,7 +3963,6 @@ impl<'a> Parser<'a> {
     // parse visiility: PUB, PRIV, or nothing
     fn parse_visibility(&mut self) -> Visibility {
         if self.eat_keyword(keywords::Pub) { Public }
-        else if self.eat_keyword(keywords::Priv) { Private }
         else { Inherited }
     }
 
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index f2f0df00ee478..53b6c09e5a30e 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -230,7 +230,6 @@ pub fn variant_to_str(var: &ast::Variant) -> ~str {
 
 pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> ~str {
     match vis {
-        ast::Private => format!("priv {}", s),
         ast::Public => format!("pub {}", s),
         ast::Inherited => s.to_owned()
     }
@@ -731,7 +730,6 @@ impl<'a> State<'a> {
 
     pub fn print_visibility(&mut self, vis: ast::Visibility) -> IoResult<()> {
         match vis {
-            ast::Private => self.word_nbsp("priv"),
             ast::Public => self.word_nbsp("pub"),
             ast::Inherited => Ok(())
         }
diff --git a/src/test/auxiliary/private_variant_xc.rs b/src/test/auxiliary/private_variant_xc.rs
deleted file mode 100644
index f9308ff749798..0000000000000
--- a/src/test/auxiliary/private_variant_xc.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-pub enum Foo {
-    Bar,
-    priv Baz,
-}
diff --git a/src/test/auxiliary/private_variant_1.rs b/src/test/auxiliary/unreachable-variant.rs
similarity index 95%
rename from src/test/auxiliary/private_variant_1.rs
rename to src/test/auxiliary/unreachable-variant.rs
index f711af43699b3..8ca85f20ab2f6 100644
--- a/src/test/auxiliary/private_variant_1.rs
+++ b/src/test/auxiliary/unreachable-variant.rs
@@ -10,6 +10,6 @@
 
 mod super_sekrit {
     pub enum sooper_sekrit {
-        quux, priv baz
+        quux, baz
     }
 }
diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs
index 4a392960a6533..453d7ffdad5c3 100644
--- a/src/test/compile-fail/assign-to-method.rs
+++ b/src/test/compile-fail/assign-to-method.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 struct cat {
-  priv meows : uint,
+  meows : uint,
 
   how_hungry : int,
 }
diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs
index 5d8932c6e6fa8..90f977168e927 100644
--- a/src/test/compile-fail/class-cast-to-trait.rs
+++ b/src/test/compile-fail/class-cast-to-trait.rs
@@ -13,7 +13,7 @@ trait noisy {
 }
 
 struct cat {
-  priv meows : uint,
+  meows : uint,
 
   how_hungry : int,
   name : ~str,
diff --git a/src/test/compile-fail/class-missing-self.rs b/src/test/compile-fail/class-missing-self.rs
index b9e7004bd7ca4..0e75e702277a3 100644
--- a/src/test/compile-fail/class-missing-self.rs
+++ b/src/test/compile-fail/class-missing-self.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 struct cat {
-  priv meows : uint,
+  meows : uint,
 }
 
 impl cat {
diff --git a/src/test/compile-fail/issue-3993-2.rs b/src/test/compile-fail/issue-3993-2.rs
index 61980abdfe7af..c5453f79de24b 100644
--- a/src/test/compile-fail/issue-3993-2.rs
+++ b/src/test/compile-fail/issue-3993-2.rs
@@ -8,12 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use zoo::{duck, goose}; //~ ERROR: variant `goose` is private
+use zoo::{duck, goose};
 
 mod zoo {
     pub enum bird {
         pub duck, //~ ERROR: unnecessary `pub` visibility
-        priv goose
+        goose
     }
 }
 
diff --git a/src/test/compile-fail/issue-9957.rs b/src/test/compile-fail/issue-9957.rs
index da90c4ee7531e..3c6a1a7b27557 100644
--- a/src/test/compile-fail/issue-9957.rs
+++ b/src/test/compile-fail/issue-9957.rs
@@ -9,15 +9,12 @@
 // except according to those terms.
 
 pub extern crate std; //~ ERROR: `pub` visibility is not allowed
-priv extern crate std; //~ ERROR: unnecessary visibility qualifier
 extern crate std;
 
 pub use std::bool;
-priv use std::bool; //~ ERROR: unnecessary visibility qualifier
 use std::bool;
 
 fn main() {
     pub use std::bool; //~ ERROR: imports in functions are never reachable
-    priv use std::bool; //~ ERROR: unnecessary visibility qualifier
     use std::bool;
 }
diff --git a/src/test/compile-fail/lint-missing-doc.rs b/src/test/compile-fail/lint-missing-doc.rs
index bf8933220bcd6..db145be6ebd24 100644
--- a/src/test/compile-fail/lint-missing-doc.rs
+++ b/src/test/compile-fail/lint-missing-doc.rs
@@ -109,8 +109,6 @@ pub enum PubBaz { //~ ERROR: missing documentation
         pub a: int, //~ ERROR: missing documentation
         b: int
     },
-
-    priv PubBazB
 }
 
 /// dox
@@ -121,7 +119,6 @@ pub enum PubBaz2 {
         pub a: int,
         b: int
     },
-    priv PubBaz2B
 }
 
 #[allow(missing_doc)]
@@ -130,7 +127,6 @@ pub enum PubBaz3 {
         pub a: int,
         b: int
     },
-    priv PubBaz3B
 }
 
 #[doc(hidden)]
diff --git a/src/test/compile-fail/lint-visible-private-types.rs b/src/test/compile-fail/lint-visible-private-types.rs
index 7c387d0cf5642..4a4032d2ab932 100644
--- a/src/test/compile-fail/lint-visible-private-types.rs
+++ b/src/test/compile-fail/lint-visible-private-types.rs
@@ -60,11 +60,6 @@ pub enum Baz {
         pub x: Private<int>, //~ ERROR private type in exported type signature
         y: Private<int>
     },
-
-    priv Baz3(Private<int>),
-    priv Baz4 {
-        x: Private<int>,
-    }
 }
 
 enum Qux {
diff --git a/src/test/compile-fail/privacy1.rs b/src/test/compile-fail/privacy1.rs
index 0aba36eebee8a..45d13bd7996a8 100644
--- a/src/test/compile-fail/privacy1.rs
+++ b/src/test/compile-fail/privacy1.rs
@@ -38,7 +38,6 @@ mod bar {
     impl B for int { fn foo() -> int { 3 } }
 
     pub enum Enum {
-        priv Priv,
         Pub
     }
 
@@ -64,7 +63,6 @@ mod bar {
     }
 
     fn test() {
-        self::Priv;
         self::Pub;
         unsafe {
             epriv();
@@ -120,7 +118,6 @@ mod foo {
                                 //~^ NOTE: trait `B` is private
         ::lol();
 
-        ::bar::Priv; //~ ERROR: variant `Priv` is private
         ::bar::Pub;
 
         unsafe {
diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs
index 858227655955c..88ab73e1f9dcf 100644
--- a/src/test/compile-fail/private-method.rs
+++ b/src/test/compile-fail/private-method.rs
@@ -12,7 +12,7 @@
 
 mod kitties {
     pub struct cat {
-        priv meows : uint,
+        meows : uint,
 
         how_hungry : int,
     }
diff --git a/src/test/compile-fail/private-variant-xc.rs b/src/test/compile-fail/private-variant-xc.rs
deleted file mode 100644
index fb80c31d4647c..0000000000000
--- a/src/test/compile-fail/private-variant-xc.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// aux-build:private_variant_xc.rs
-
-extern crate private_variant_xc;
-
-pub fn main() {
-    let _ = private_variant_xc::Bar;
-    let _ = private_variant_xc::Baz;    //~ ERROR variant `Baz` is private
-}
diff --git a/src/test/compile-fail/private-variant.rs b/src/test/compile-fail/private-variant.rs
deleted file mode 100644
index d63d04c90ccca..0000000000000
--- a/src/test/compile-fail/private-variant.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-mod a {
-    pub enum Waffle {
-        Belgian,
-        Brussels,
-        priv Liege
-    }
-}
-
-fn main() {
-    let x = a::Liege;   //~ ERROR variant `Liege` is private
-}
diff --git a/src/test/compile-fail/removed-syntax-priv-group.rs b/src/test/compile-fail/removed-syntax-priv-group.rs
deleted file mode 100644
index 8fbad2df00207..0000000000000
--- a/src/test/compile-fail/removed-syntax-priv-group.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-struct sss {
-    bar: int,
-    priv {
-    //~^ ERROR expected ident
-        foo: ()
-    }
-}
diff --git a/src/test/compile-fail/unnecessary-private.rs b/src/test/compile-fail/unnecessary-private.rs
index 69a33922776e1..abbb084dbc043 100644
--- a/src/test/compile-fail/unnecessary-private.rs
+++ b/src/test/compile-fail/unnecessary-private.rs
@@ -19,7 +19,7 @@ fn main() {
     }
 
     struct D {
-        priv foo: int, //~ ERROR: visibility has no effect
+        pub foo: int, //~ ERROR: visibility has no effect
     }
     pub fn foo() {} //~ ERROR: visibility has no effect
     pub mod bar {} //~ ERROR: visibility has no effect
diff --git a/src/test/compile-fail/private_variant_2.rs b/src/test/compile-fail/unreachable-variant.rs
similarity index 77%
rename from src/test/compile-fail/private_variant_2.rs
rename to src/test/compile-fail/unreachable-variant.rs
index e4dd4b75fd4a8..566b888099ca6 100644
--- a/src/test/compile-fail/private_variant_2.rs
+++ b/src/test/compile-fail/unreachable-variant.rs
@@ -8,10 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// aux-build:private_variant_1.rs
+// aux-build:unreachable-variant.rs
 
-extern crate private_variant_1;
+extern crate other = "unreachable-variant";
 
 fn main() {
-    let _x = private_variant_1::super_sekrit::baz; //~ ERROR is private
+    let _x = other::super_sekrit::baz; //~ ERROR is private
 }
diff --git a/src/test/compile-fail/useless-priv.rs b/src/test/compile-fail/useless-priv.rs
index 5a4dd42f49d3d..bb39107463e11 100644
--- a/src/test/compile-fail/useless-priv.rs
+++ b/src/test/compile-fail/useless-priv.rs
@@ -9,9 +9,7 @@
 // except according to those terms.
 
 struct A { pub i: int }
-struct B { priv i: int }        //~ ERROR: unnecessary `priv`
 pub enum C { pub Variant }      //~ ERROR: unnecessary `pub`
-enum D { priv Variant2 }        //~ ERROR: unnecessary `priv`
 
 pub trait E {
     pub fn foo() {}             //~ ERROR: unnecessary visibility

From a0347d5224977c8a271fbae64d084a5c5347d22b Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Tue, 15 Apr 2014 19:32:42 -0700
Subject: [PATCH 3/3] syntax: Demote `priv` to a reserved keyword

It is no longer used in rust anywhere.

RFC: 0006-remove-priv
---
 src/libsyntax/parse/token.rs | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 101c748b1ec05..de6dacbe766c2 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -461,29 +461,29 @@ declare_special_idents_and_keywords! {
         (25,                         Mod,        "mod");
         (26,                         Mut,        "mut");
         (27,                         Once,       "once");
-        (28,                         Priv,       "priv");
-        (29,                         Pub,        "pub");
-        (30,                         Ref,        "ref");
-        (31,                         Return,     "return");
+        (28,                         Pub,        "pub");
+        (29,                         Ref,        "ref");
+        (30,                         Return,     "return");
         // Static and Self are also special idents (prefill de-dupes)
         (super::STATIC_KEYWORD_NAME, Static,     "static");
         (super::SELF_KEYWORD_NAME,   Self,       "self");
-        (32,                         Struct,     "struct");
-        (33,                         Super,      "super");
-        (34,                         True,       "true");
-        (35,                         Trait,      "trait");
-        (36,                         Type,       "type");
-        (37,                         Unsafe,     "unsafe");
-        (38,                         Use,        "use");
-        (39,                         While,      "while");
-        (40,                         Continue,   "continue");
-        (41,                         Proc,       "proc");
-        (42,                         Box,        "box");
+        (31,                         Struct,     "struct");
+        (32,                         Super,      "super");
+        (33,                         True,       "true");
+        (34,                         Trait,      "trait");
+        (35,                         Type,       "type");
+        (36,                         Unsafe,     "unsafe");
+        (37,                         Use,        "use");
+        (38,                         While,      "while");
+        (39,                         Continue,   "continue");
+        (40,                         Proc,       "proc");
+        (41,                         Box,        "box");
 
         'reserved:
-        (43,                         Alignof,    "alignof");
-        (44,                         Be,         "be");
-        (45,                         Offsetof,   "offsetof");
+        (42,                         Alignof,    "alignof");
+        (43,                         Be,         "be");
+        (44,                         Offsetof,   "offsetof");
+        (45,                         Priv,       "priv");
         (46,                         Pure,       "pure");
         (47,                         Sizeof,     "sizeof");
         (48,                         Typeof,     "typeof");