Skip to content

Commit 3d76a23

Browse files
committed
libstd: Remove all newtype enums from std and core.
1 parent e6f7ff3 commit 3d76a23

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

src/libcore/task/spawn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct AncestorNode {
151151
mut ancestors: AncestorList,
152152
}
153153

154-
enum AncestorList = Option<unstable::Exclusive<AncestorNode>>;
154+
struct AncestorList(Option<unstable::Exclusive<AncestorNode>>);
155155

156156
// Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety.
157157
#[inline(always)]

src/librustdoc/extract.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ fn structdoc_from_struct(
322322
fields: do struct_def.fields.map |field| {
323323
match field.node.kind {
324324
ast::named_field(ident, _, _) => to_str(ident),
325-
ast::unnamed_field => fail!(
326-
~"what is an unnamed struct field?")
325+
ast::unnamed_field => ~"(unnamed)",
327326
}
328327
},
329328
sig: None

src/libstd/arc.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,11 @@ pub impl<T:Const + Owned> RWARC<T> {
365365
let state = get_shared_mutable_state(&self.x);
366366
do (*borrow_rwlock(state)).write_downgrade |write_mode| {
367367
check_poison(false, (*state).failed);
368-
blk(RWWriteMode((&mut (*state).data,
369-
write_mode,
370-
PoisonOnFail(&mut (*state).failed))))
368+
blk(RWWriteMode {
369+
data: &mut (*state).data,
370+
token: write_mode,
371+
poison: PoisonOnFail(&mut (*state).failed)
372+
})
371373
}
372374
}
373375
}
@@ -376,7 +378,11 @@ pub impl<T:Const + Owned> RWARC<T> {
376378
fn downgrade(&self, token: RWWriteMode/&a<T>) -> RWReadMode/&a<T> {
377379
// The rwlock should assert that the token belongs to us for us.
378380
let state = unsafe { get_shared_immutable_state(&self.x) };
379-
let RWWriteMode((data, t, _poison)) = token;
381+
let RWWriteMode {
382+
data: data,
383+
token: t,
384+
poison: _poison
385+
} = token;
380386
// Let readers in
381387
let new_token = (&state.lock).downgrade(t);
382388
// Whatever region the input reference had, it will be safe to use
@@ -386,7 +392,10 @@ pub impl<T:Const + Owned> RWARC<T> {
386392
// Downgrade ensured the token belonged to us. Just a sanity check.
387393
fail_unless!(ptr::ref_eq(&state.data, new_data));
388394
// Produce new token
389-
RWReadMode((new_data, new_token))
395+
RWReadMode {
396+
data: new_data,
397+
token: new_token,
398+
}
390399
}
391400
}
392401
@@ -398,19 +407,28 @@ fn borrow_rwlock<T:Const + Owned>(state: *const RWARCInner<T>) -> *RWlock {
398407
unsafe { cast::transmute(&const (*state).lock) }
399408
}
400409
401-
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
402-
403410
/// The "write permission" token used for RWARC.write_downgrade().
404-
pub enum RWWriteMode<T> =
405-
(&self/mut T, sync::RWlockWriteMode/&self, PoisonOnFail);
411+
pub struct RWWriteMode<'self, T> {
412+
data: &'self mut T,
413+
token: sync::RWlockWriteMode<'self>,
414+
poison: PoisonOnFail,
415+
}
416+
406417
/// The "read permission" token used for RWARC.write_downgrade().
407-
pub enum RWReadMode<T> = (&self/T, sync::RWlockReadMode/&self);
418+
pub struct RWReadMode<'self, T> {
419+
data: &'self T,
420+
token: sync::RWlockReadMode<'self>,
421+
}
408422

409423
pub impl<T:Const + Owned> RWWriteMode/&self<T> {
410424
/// Access the pre-downgrade RWARC in write mode.
411425
fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
412426
match *self {
413-
RWWriteMode((ref data, ref token, _)) => {
427+
RWWriteMode {
428+
data: ref data,
429+
token: ref token,
430+
poison: _
431+
} => {
414432
do token.write {
415433
blk(&mut **data)
416434
}
@@ -420,7 +438,11 @@ pub impl<T:Const + Owned> RWWriteMode/&self<T> {
420438
/// Access the pre-downgrade RWARC in write mode with a condvar.
421439
fn write_cond<U>(&self, blk: &fn(x: &x/mut T, c: &c/Condvar) -> U) -> U {
422440
match *self {
423-
RWWriteMode((ref data, ref token, ref poison)) => {
441+
RWWriteMode {
442+
data: ref data,
443+
token: ref token,
444+
poison: ref poison
445+
} => {
424446
do token.write_cond |cond| {
425447
unsafe {
426448
let cvar = Condvar {
@@ -440,7 +462,10 @@ pub impl<T:Const + Owned> RWReadMode/&self<T> {
440462
/// Access the post-downgrade rwlock in read mode.
441463
fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
442464
match *self {
443-
RWReadMode((data, ref token)) => {
465+
RWReadMode {
466+
data: data,
467+
token: ref token
468+
} => {
444469
do token.read { blk(data) }
445470
}
446471
}

src/libstd/sync.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ struct SemInner<Q> {
7979
// a condition variable attached, others should.
8080
blocked: Q
8181
}
82+
8283
#[doc(hidden)]
83-
enum Sem<Q> = Exclusive<SemInner<Q>>;
84+
struct Sem<Q>(Exclusive<SemInner<Q>>);
8485

8586
#[doc(hidden)]
8687
fn new_sem<Q:Owned>(count: int, q: Q) -> Sem<Q> {

0 commit comments

Comments
 (0)