From 4faf63e472f1cd8721be6c498e4db97760665e90 Mon Sep 17 00:00:00 2001
From: Patrick Walton <pcwalton@mimiga.net>
Date: Thu, 7 Mar 2013 17:23:14 -0800
Subject: [PATCH] libstd: Remove all newtype enums from std and core.

---
 src/libcore/task/spawn.rs |  2 +-
 src/librustdoc/extract.rs |  3 +--
 src/libstd/arc.rs         | 51 +++++++++++++++++++++++++++++----------
 src/libstd/sync.rs        |  3 ++-
 4 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs
index 617149f7fd5..a0db2525441 100644
--- a/src/libcore/task/spawn.rs
+++ b/src/libcore/task/spawn.rs
@@ -151,7 +151,7 @@ struct AncestorNode {
     mut ancestors:    AncestorList,
 }
 
-enum AncestorList = Option<unstable::Exclusive<AncestorNode>>;
+struct AncestorList(Option<unstable::Exclusive<AncestorNode>>);
 
 // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
 #[inline(always)]
diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs
index fc784722b25..5e5c843da26 100644
--- a/src/librustdoc/extract.rs
+++ b/src/librustdoc/extract.rs
@@ -322,8 +322,7 @@ fn structdoc_from_struct(
         fields: do struct_def.fields.map |field| {
             match field.node.kind {
                 ast::named_field(ident, _, _) => to_str(ident),
-                ast::unnamed_field => fail!(
-                    ~"what is an unnamed struct field?")
+                ast::unnamed_field => ~"(unnamed)",
             }
         },
         sig: None
diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs
index 46e6980be58..d7d878fa192 100644
--- a/src/libstd/arc.rs
+++ b/src/libstd/arc.rs
@@ -365,9 +365,11 @@ pub impl<T:Const + Owned> RWARC<T> {
             let state = get_shared_mutable_state(&self.x);
             do (*borrow_rwlock(state)).write_downgrade |write_mode| {
                 check_poison(false, (*state).failed);
-                blk(RWWriteMode((&mut (*state).data,
-                                 write_mode,
-                                 PoisonOnFail(&mut (*state).failed))))
+                blk(RWWriteMode {
+                    data: &mut (*state).data,
+                    token: write_mode,
+                    poison: PoisonOnFail(&mut (*state).failed)
+                })
             }
         }
     }
@@ -376,7 +378,11 @@ pub impl<T:Const + Owned> RWARC<T> {
     fn downgrade(&self, token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> {
         // The rwlock should assert that the token belongs to us for us.
         let state = unsafe { get_shared_immutable_state(&self.x) };
-        let RWWriteMode((data, t, _poison)) = token;
+        let RWWriteMode {
+            data: data,
+            token: t,
+            poison: _poison
+        } = token;
         // Let readers in
         let new_token = (&state.lock).downgrade(t);
         // Whatever region the input reference had, it will be safe to use
@@ -386,7 +392,10 @@ pub impl<T:Const + Owned> RWARC<T> {
         // Downgrade ensured the token belonged to us. Just a sanity check.
         fail_unless!(ptr::ref_eq(&state.data, new_data));
         // Produce new token
-        RWReadMode((new_data, new_token))
+        RWReadMode {
+            data: new_data,
+            token: new_token,
+        }
     }
 }
 
@@ -398,19 +407,28 @@ fn borrow_rwlock<T:Const + Owned>(state: *const RWARCInner<T>) -> *RWlock {
     unsafe { cast::transmute(&const (*state).lock) }
 }
 
-// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
-
 /// The "write permission" token used for RWARC.write_downgrade().
-pub enum RWWriteMode<T> =
-    (&self/mut T, sync::RWlockWriteMode/&self, PoisonOnFail);
+pub struct RWWriteMode<'self, T> {
+    data: &'self mut T,
+    token: sync::RWlockWriteMode<'self>,
+    poison: PoisonOnFail,
+}
+
 /// The "read permission" token used for RWARC.write_downgrade().
-pub enum RWReadMode<T> = (&self/T, sync::RWlockReadMode/&self);
+pub struct RWReadMode<'self, T> {
+    data: &'self T,
+    token: sync::RWlockReadMode<'self>,
+}
 
 pub impl<T:Const + Owned> RWWriteMode/&self<T> {
     /// Access the pre-downgrade RWARC in write mode.
     fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
         match *self {
-            RWWriteMode((ref data, ref token, _)) => {
+            RWWriteMode {
+                data: ref data,
+                token: ref token,
+                poison: _
+            } => {
                 do token.write {
                     blk(&mut **data)
                 }
@@ -420,7 +438,11 @@ pub impl<T:Const + Owned> RWWriteMode/&self<T> {
     /// Access the pre-downgrade RWARC in write mode with a condvar.
     fn write_cond<U>(&self, blk: &fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
         match *self {
-            RWWriteMode((ref data, ref token, ref poison)) => {
+            RWWriteMode {
+                data: ref data,
+                token: ref token,
+                poison: ref poison
+            } => {
                 do token.write_cond |cond| {
                     unsafe {
                         let cvar = Condvar {
@@ -440,7 +462,10 @@ pub impl<T:Const + Owned> RWReadMode/&self<T> {
     /// Access the post-downgrade rwlock in read mode.
     fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
         match *self {
-            RWReadMode((data, ref token)) => {
+            RWReadMode {
+                data: data,
+                token: ref token
+            } => {
                 do token.read { blk(data) }
             }
         }
diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs
index a68fe5f10a3..2190475d943 100644
--- a/src/libstd/sync.rs
+++ b/src/libstd/sync.rs
@@ -79,8 +79,9 @@ struct SemInner<Q> {
     // a condition variable attached, others should.
     blocked:   Q
 }
+
 #[doc(hidden)]
-enum Sem<Q> = Exclusive<SemInner<Q>>;
+struct Sem<Q>(Exclusive<SemInner<Q>>);
 
 #[doc(hidden)]
 fn new_sem<Q:Owned>(count: int, q: Q) -> Sem<Q> {