diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index ba6862039d44d..a62e5ff9d3274 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -158,17 +158,10 @@ fn run_tests(config: config) { } fn test_opts(config: config) -> test::TestOpts { - {filter: - match config.filter { - option::Some(s) => option::Some(s), - option::None => option::None - }, - run_ignored: config.run_ignored, - logfile: - match config.logfile { - option::Some(s) => option::Some(s.to_str()), - option::None => option::None - } + test::TestOpts { + filter: config.filter, + run_ignored: config.run_ignored, + logfile: config.logfile.map(|s| s.to_str()), } } diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 1aa6c5a01972f..4f0d76d69f32c 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -28,28 +28,26 @@ use option::{None, Option, Some}; use option; use vec; -type DListLink = Option>; +pub type DListLink = Option<@DListNode>; -enum DListNode = @{ +pub struct DListNode { data: T, mut linked: bool, // for assertions mut prev: DListLink, - mut next: DListLink -}; - -pub enum DList { - DList_(@{ - mut size: uint, - mut hd: DListLink, - mut tl: DListLink - }) + mut next: DListLink, +} + +pub struct DList { + mut size: uint, + mut hd: DListLink, + mut tl: DListLink, } priv impl DListNode { - pure fn assert_links() { + pure fn assert_links(@self) { match self.next { Some(neighbour) => match neighbour.prev { - Some(me) => if !managed::ptr_eq(*self, *me) { + Some(me) => if !managed::ptr_eq(self, me) { fail ~"Asymmetric next-link in dlist node." }, None => fail ~"One-way next-link in dlist node." @@ -58,7 +56,7 @@ priv impl DListNode { } match self.prev { Some(neighbour) => match neighbour.next { - Some(me) => if !managed::ptr_eq(*me, *self) { + Some(me) => if !managed::ptr_eq(me, self) { fail ~"Asymmetric prev-link in dlist node." }, None => fail ~"One-way prev-link in dlist node." @@ -70,24 +68,24 @@ priv impl DListNode { impl DListNode { /// Get the next node in the list, if there is one. - pure fn next_link() -> Option> { + pure fn next_link(@self) -> DListLink { self.assert_links(); self.next } /// Get the next node in the list, failing if there isn't one. - pure fn next_node() -> DListNode { + pure fn next_node(@self) -> @DListNode { match self.next_link() { Some(nobe) => nobe, None => fail ~"This dlist node has no next neighbour." } } /// Get the previous node in the list, if there is one. - pure fn prev_link() -> Option> { + pure fn prev_link(@self) -> DListLink { self.assert_links(); self.prev } /// Get the previous node in the list, failing if there isn't one. - pure fn prev_node() -> DListNode { + pure fn prev_node(@self) -> @DListNode { match self.prev_link() { Some(nobe) => nobe, None => fail ~"This dlist node has no previous neighbour." @@ -96,24 +94,23 @@ impl DListNode { } /// Creates a new dlist node with the given data. -pub pure fn new_dlist_node(data: T) -> DListNode { - DListNode(@{data: move data, mut linked: false, - mut prev: None, mut next: None}) +pub pure fn new_dlist_node(data: T) -> @DListNode { + @DListNode { data: data, linked: false, prev: None, next: None } } /// Creates a new, empty dlist. -pub pure fn DList() -> DList { - DList_(@{mut size: 0, mut hd: None, mut tl: None}) +pub pure fn DList() -> @DList { + @DList { size: 0, hd: None, tl: None } } /// Creates a new dlist with a single element -pub pure fn from_elem(data: T) -> DList { +pub pure fn from_elem(data: T) -> @DList { let list = DList(); - unsafe { list.push(move data); } + unsafe { list.push(data); } list } -pub fn from_vec(vec: &[T]) -> DList { +pub fn from_vec(vec: &[T]) -> @DList { do vec::foldl(DList(), vec) |list,data| { list.push(*data); // Iterating left-to-right -- add newly to the tail. list @@ -122,7 +119,7 @@ pub fn from_vec(vec: &[T]) -> DList { /// Produce a list from a list of lists, leaving no elements behind in the /// input. O(number of sub-lists). -pub fn concat(lists: DList>) -> DList { +pub fn concat(lists: @DList<@DList>) -> @DList { let result = DList(); while !lists.is_empty() { result.append(lists.pop().get()); @@ -131,11 +128,10 @@ pub fn concat(lists: DList>) -> DList { } priv impl DList { - pure fn new_link(data: T) -> DListLink { - Some(DListNode(@{data: move data, mut linked: true, - mut prev: None, mut next: None})) + static pure fn new_link(data: T) -> DListLink { + Some(@DListNode { data: data, linked: true, prev: None, next: None }) } - pure fn assert_mine(nobe: DListNode) { + pure fn assert_mine(@self, nobe: @DListNode) { // These asserts could be stronger if we had node-root back-pointers, // but those wouldn't allow for O(1) append. if self.size == 0 { @@ -143,15 +139,15 @@ priv impl DList { } if !nobe.linked { fail ~"That node isn't linked to any dlist." } if !((nobe.prev.is_some() - || managed::ptr_eq(*self.hd.expect(~"headless dlist?"), - *nobe)) && + || managed::ptr_eq(self.hd.expect(~"headless dlist?"), + nobe)) && (nobe.next.is_some() - || managed::ptr_eq(*self.tl.expect(~"tailless dlist?"), - *nobe))) { + || managed::ptr_eq(self.tl.expect(~"tailless dlist?"), + nobe))) { fail ~"That node isn't on this dlist." } } - fn make_mine(nobe: DListNode) { + fn make_mine(nobe: @DListNode) { if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked { fail ~"Cannot insert node that's already on a dlist!" } @@ -171,7 +167,7 @@ priv impl DList { } } // Remove a node from the list. - fn unlink(nobe: DListNode) { + fn unlink(@self, nobe: @DListNode) { self.assert_mine(nobe); assert self.size > 0; self.link(nobe.prev, nobe.next); @@ -181,24 +177,24 @@ priv impl DList { self.size -= 1; } - fn add_head(nobe: DListLink) { + fn add_head(@self, nobe: DListLink) { self.link(nobe, self.hd); // Might set tail too. self.hd = nobe; self.size += 1; } - fn add_tail(nobe: DListLink) { + fn add_tail(@self, nobe: DListLink) { self.link(self.tl, nobe); // Might set head too. self.tl = nobe; self.size += 1; } - fn insert_left(nobe: DListLink, neighbour: DListNode) { + fn insert_left(@self, nobe: DListLink, neighbour: @DListNode) { self.assert_mine(neighbour); assert self.size > 0; self.link(neighbour.prev, nobe); self.link(nobe, Some(neighbour)); self.size += 1; } - fn insert_right(neighbour: DListNode, nobe: DListLink) { + fn insert_right(@self, neighbour: @DListNode, nobe: DListLink) { self.assert_mine(neighbour); assert self.size > 0; self.link(nobe, neighbour.next); @@ -209,50 +205,50 @@ priv impl DList { impl DList { /// Get the size of the list. O(1). - pure fn len() -> uint { self.size } + pure fn len(@self) -> uint { self.size } /// Returns true if the list is empty. O(1). - pure fn is_empty() -> bool { self.len() == 0 } + pure fn is_empty(@self) -> bool { self.len() == 0 } /// Returns true if the list is not empty. O(1). - pure fn is_not_empty() -> bool { self.len() != 0 } + pure fn is_not_empty(@self) -> bool { self.len() != 0 } /// Add data to the head of the list. O(1). - fn push_head(data: T) { - self.add_head(self.new_link(move data)); + fn push_head(@self, data: T) { + self.add_head(DList::new_link(data)); } /** * Add data to the head of the list, and get the new containing * node. O(1). */ - fn push_head_n(data: T) -> DListNode { - let mut nobe = self.new_link(move data); + fn push_head_n(@self, data: T) -> @DListNode { + let mut nobe = DList::new_link(data); self.add_head(nobe); - option::get(nobe) + nobe.get() } /// Add data to the tail of the list. O(1). - fn push(data: T) { - self.add_tail(self.new_link(move data)); + fn push(@self, data: T) { + self.add_tail(DList::new_link(data)); } /** * Add data to the tail of the list, and get the new containing * node. O(1). */ - fn push_n(data: T) -> DListNode { - let mut nobe = self.new_link(move data); + fn push_n(@self, data: T) -> @DListNode { + let mut nobe = DList::new_link(data); self.add_tail(nobe); - option::get(nobe) + nobe.get() } /** * Insert data into the middle of the list, left of the given node. * O(1). */ - fn insert_before(data: T, neighbour: DListNode) { - self.insert_left(self.new_link(move data), neighbour); + fn insert_before(@self, data: T, neighbour: @DListNode) { + self.insert_left(DList::new_link(data), neighbour); } /** * Insert an existing node in the middle of the list, left of the * given node. O(1). */ - fn insert_n_before(nobe: DListNode, neighbour: DListNode) { + fn insert_n_before(@self, nobe: @DListNode, neighbour: @DListNode) { self.make_mine(nobe); self.insert_left(Some(nobe), neighbour); } @@ -260,23 +256,27 @@ impl DList { * Insert data in the middle of the list, left of the given node, * and get its containing node. O(1). */ - fn insert_before_n(data: T, neighbour: DListNode) -> DListNode { - let mut nobe = self.new_link(move data); + fn insert_before_n( + @self, + data: T, + neighbour: @DListNode + ) -> @DListNode { + let mut nobe = DList::new_link(data); self.insert_left(nobe, neighbour); - option::get(nobe) + nobe.get() } /** * Insert data into the middle of the list, right of the given node. * O(1). */ - fn insert_after(data: T, neighbour: DListNode) { - self.insert_right(neighbour, self.new_link(move data)); + fn insert_after(@self, data: T, neighbour: @DListNode) { + self.insert_right(neighbour, DList::new_link(data)); } /** * Insert an existing node in the middle of the list, right of the * given node. O(1). */ - fn insert_n_after(nobe: DListNode, neighbour: DListNode) { + fn insert_n_after(@self, nobe: @DListNode, neighbour: @DListNode) { self.make_mine(nobe); self.insert_right(neighbour, Some(nobe)); } @@ -284,38 +284,42 @@ impl DList { * Insert data in the middle of the list, right of the given node, * and get its containing node. O(1). */ - fn insert_after_n(data: T, neighbour: DListNode) -> DListNode { - let mut nobe = self.new_link(move data); + fn insert_after_n( + @self, + data: T, + neighbour: @DListNode + ) -> @DListNode { + let mut nobe = DList::new_link(data); self.insert_right(neighbour, nobe); - option::get(nobe) + nobe.get() } /// Remove a node from the head of the list. O(1). - fn pop_n() -> Option> { + fn pop_n(@self) -> DListLink { let hd = self.peek_n(); hd.map(|nobe| self.unlink(*nobe)); hd } /// Remove a node from the tail of the list. O(1). - fn pop_tail_n() -> Option> { + fn pop_tail_n(@self) -> DListLink { let tl = self.peek_tail_n(); tl.map(|nobe| self.unlink(*nobe)); tl } /// Get the node at the list's head. O(1). - pure fn peek_n() -> Option> { self.hd } + pure fn peek_n(@self) -> DListLink { self.hd } /// Get the node at the list's tail. O(1). - pure fn peek_tail_n() -> Option> { self.tl } + pure fn peek_tail_n(@self) -> DListLink { self.tl } /// Get the node at the list's head, failing if empty. O(1). - pure fn head_n() -> DListNode { + pure fn head_n(@self) -> @DListNode { match self.hd { Some(nobe) => nobe, None => fail ~"Attempted to get the head of an empty dlist." } } /// Get the node at the list's tail, failing if empty. O(1). - pure fn tail_n() -> DListNode { + pure fn tail_n(@self) -> @DListNode { match self.tl { Some(nobe) => nobe, None => fail ~"Attempted to get the tail of an empty dlist." @@ -323,14 +327,14 @@ impl DList { } /// Remove a node from anywhere in the list. O(1). - fn remove(nobe: DListNode) { self.unlink(nobe); } + fn remove(@self, nobe: @DListNode) { self.unlink(nobe); } /** * Empty another list onto the end of this list, joining this list's tail * to the other list's head. O(1). */ - fn append(them: DList) { - if managed::ptr_eq(*self, *them) { + fn append(@self, them: @DList) { + if managed::ptr_eq(self, them) { fail ~"Cannot append a dlist to itself!" } if them.len() > 0 { @@ -346,8 +350,8 @@ impl DList { * Empty another list onto the start of this list, joining the other * list's tail to this list's head. O(1). */ - fn prepend(them: DList) { - if managed::ptr_eq(*self, *them) { + fn prepend(@self, them: @DList) { + if managed::ptr_eq(self, them) { fail ~"Cannot prepend a dlist to itself!" } if them.len() > 0 { @@ -361,7 +365,7 @@ impl DList { } /// Reverse the list's elements in place. O(n). - fn reverse() { + fn reverse(@self) { do option::while_some(self.hd) |nobe| { let next_nobe = nobe.next; self.remove(nobe); @@ -375,7 +379,7 @@ impl DList { * Remove everything from the list. This is important because the cyclic * links won't otherwise be automatically refcounted-collected. O(n). */ - fn clear() { + fn clear(@self) { // Cute as it would be to simply detach the list and proclaim "O(1)!", // the GC would still be a hidden O(n). Better to be honest about it. while !self.is_empty() { @@ -384,7 +388,7 @@ impl DList { } /// Iterate over nodes. - pure fn each_node(f: fn(DListNode) -> bool) { + pure fn each_node(@self, f: fn(@DListNode) -> bool) { let mut link = self.peek_n(); while link.is_some() { let nobe = link.get(); @@ -394,26 +398,26 @@ impl DList { } /// Check data structure integrity. O(n). - fn assert_consistent() { - if option::is_none(&self.hd) || option::is_none(&self.tl) { - assert option::is_none(&self.hd) && option::is_none(&self.tl); + fn assert_consistent(@self) { + if self.hd.is_none() || self.tl.is_none() { + assert self.hd.is_none() && self.tl.is_none(); } // iterate forwards let mut count = 0; let mut link = self.peek_n(); let mut rabbit = link; - while option::is_some(&link) { - let nobe = option::get(link); + while link.is_some() { + let nobe = link.get(); assert nobe.linked; // check cycle - if option::is_some(&rabbit) { - rabbit = option::get(rabbit).next; + if rabbit.is_some() { + rabbit = rabbit.get().next; } - if option::is_some(&rabbit) { - rabbit = option::get(rabbit).next; + if rabbit.is_some() { + rabbit = rabbit.get().next; } - if option::is_some(&rabbit) { - assert !managed::ptr_eq(*option::get(rabbit), *nobe); + if rabbit.is_some() { + assert !managed::ptr_eq(rabbit.get(), nobe); } // advance link = nobe.next_link(); @@ -423,18 +427,18 @@ impl DList { // iterate backwards - some of this is probably redundant. link = self.peek_tail_n(); rabbit = link; - while option::is_some(&link) { - let nobe = option::get(link); + while link.is_some() { + let nobe = link.get(); assert nobe.linked; // check cycle - if option::is_some(&rabbit) { - rabbit = option::get(rabbit).prev; + if rabbit.is_some() { + rabbit = rabbit.get().prev; } - if option::is_some(&rabbit) { - rabbit = option::get(rabbit).prev; + if rabbit.is_some() { + rabbit = rabbit.get().prev; } - if option::is_some(&rabbit) { - assert !managed::ptr_eq(*option::get(rabbit), *nobe); + if rabbit.is_some() { + assert !managed::ptr_eq(rabbit.get(), nobe); } // advance link = nobe.prev_link(); @@ -446,21 +450,33 @@ impl DList { impl DList { /// Remove data from the head of the list. O(1). - fn pop() -> Option { self.pop_n().map (|nobe| nobe.data) } + fn pop(@self) -> Option { + self.pop_n().map(|nobe| nobe.data) + } + /// Remove data from the tail of the list. O(1). - fn pop_tail() -> Option { self.pop_tail_n().map (|nobe| nobe.data) } + fn pop_tail(@self) -> Option { + self.pop_tail_n().map(|nobe| nobe.data) + } + /// Get data at the list's head. O(1). - pure fn peek() -> Option { self.peek_n().map (|nobe| nobe.data) } + pure fn peek(@self) -> Option { + self.peek_n().map(|nobe| nobe.data) + } + /// Get data at the list's tail. O(1). - pure fn peek_tail() -> Option { + pure fn peek_tail(@self) -> Option { self.peek_tail_n().map (|nobe| nobe.data) } + /// Get data at the list's head, failing if empty. O(1). - pure fn head() -> T { self.head_n().data } + pure fn head(@self) -> T { self.head_n().data } + /// Get data at the list's tail, failing if empty. O(1). - pure fn tail() -> T { self.tail_n().data } + pure fn tail(@self) -> T { self.tail_n().data } + /// Get the elements of the list as a vector. O(n). - pure fn to_vec() -> ~[T] { + pure fn to_vec(@self) -> ~[T] { let mut v = vec::with_capacity(self.size); unsafe { // Take this out of the unchecked when iter's functions are pure diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 420c113443e45..854f99be1e2d1 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -376,13 +376,23 @@ pub mod ct { fn test_parse_fmt_string() { assert parse_fmt_string("foo %s bar", die) == ~[ PieceString(~"foo "), - PieceConv(Conv {param: None, flags: ~[], width: CountImplied, - precision: CountImplied, ty: TyStr}), + PieceConv(Conv { + param: None, + flags: ~[], + width: CountImplied, + precision: CountImplied, + ty: TyStr, + }), PieceString(~" bar")]; assert parse_fmt_string("%s", die) == ~[ - PieceConv(Conv {param: None, flags: ~[], width: CountImplied, - precision: CountImplied, ty: TyStr })]; + PieceConv(Conv { + param: None, + flags: ~[], + width: CountImplied, + precision: CountImplied, + ty: TyStr, + })]; assert parse_fmt_string("%%%%", die) == ~[ PieceString(~"%"), PieceString(~"%")]; @@ -466,7 +476,7 @@ pub mod ct { // Functions used by the fmt extension at runtime. For now there are a lot of // decisions made a runtime. If it proves worthwhile then some of these // conditions can be evaluated at compile-time. For now though it's cleaner to -// implement it 0this way, I think. +// implement it this way, I think. #[doc(hidden)] pub mod rt { use float; @@ -486,8 +496,19 @@ pub mod rt { pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, } + #[cfg(stage0)] pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty}; + #[cfg(stage1)] + #[cfg(stage2)] + #[cfg(stage3)] + pub struct Conv { + flags: u32, + width: Count, + precision: Count, + ty: Ty, + } + pub pure fn conv_int(cv: Conv, i: int) -> ~str { let radix = 10; let prec = get_int_precision(cv); diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index d27681d46300b..698e264b57a65 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -87,7 +87,10 @@ unsafe fn get_safe_point_count() -> uint { return *module_meta; } -type SafePoint = { sp_meta: *Word, fn_meta: *Word }; +struct SafePoint { + sp_meta: *Word, + fn_meta: *Word, +} // Returns the safe point metadata for the given program counter, if // any. @@ -106,7 +109,10 @@ unsafe fn is_safe_point(pc: *Word) -> Option { let sp: **Word = bump(safe_points, spi*3); let sp_loc = *sp; if sp_loc == pc { - return Some({sp_meta: *bump(sp, 1), fn_meta: *bump(sp, 2)}); + return Some(SafePoint { + sp_meta: *bump(sp, 1), + fn_meta: *bump(sp, 2), + }); } spi += 1; } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 9b5f271a61121..fedcb9511960e 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -455,10 +455,15 @@ impl *libc::FILE: Reader { } } +struct Wrapper { + base: T, + cleanup: C, +} + // A forwarding impl of reader that also holds on to a resource for the // duration of its lifetime. // FIXME there really should be a better way to do this // #2004 -impl {base: T, cleanup: C}: Reader { +impl Wrapper: Reader { fn read(&self, bytes: &[mut u8], len: uint) -> uint { self.base.read(bytes, len) } @@ -487,7 +492,7 @@ pub fn FILERes(f: *libc::FILE) -> FILERes { pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader { if cleanup { - {base: f, cleanup: FILERes(f)} as Reader + Wrapper { base: f, cleanup: FILERes(f) } as Reader } else { f as Reader } @@ -587,7 +592,7 @@ pub trait Writer { fn get_type(&self) -> WriterType; } -impl {base: T, cleanup: C}: Writer { +impl Wrapper: Writer { fn write(&self, bs: &[const u8]) { self.base.write(bs); } fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); } fn tell(&self) -> uint { self.base.tell() } @@ -639,7 +644,7 @@ impl *libc::FILE: Writer { pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer { if cleanup { - {base: f, cleanup: FILERes(f)} as Writer + Wrapper { base: f, cleanup: FILERes(f) } as Writer } else { f as Writer } @@ -696,7 +701,7 @@ pub fn FdRes(fd: fd_t) -> FdRes { pub fn fd_writer(fd: fd_t, cleanup: bool) -> Writer { if cleanup { - {base: fd, cleanup: FdRes(fd)} as Writer + Wrapper { base: fd, cleanup: FdRes(fd) } as Writer } else { fd as Writer } @@ -1086,11 +1091,9 @@ pub fn read_whole_file(file: &Path) -> Result<~[u8], ~str> { // fsync related pub mod fsync { + use prelude::*; use io::{FILERes, FdRes, fd_t}; - use kinds::Copy; use libc; - use option::Option; - use option; use os; pub enum Level { @@ -1110,10 +1113,13 @@ pub mod fsync { // Artifacts that need to fsync on destruction pub struct Res { arg: Arg, - drop { + } + + impl Res: Drop { + fn finalize(&self) { match self.arg.opt_level { - option::None => (), - option::Some(level) => { + None => (), + Some(level) => { // fail hard if not succesful assert((self.arg.fsync_fn)(self.arg.val, level) != -1); } @@ -1127,11 +1133,11 @@ pub mod fsync { } } - pub type Arg = { + pub struct Arg { val: t, opt_level: Option, - fsync_fn: fn@(f: t, Level) -> int - }; + fsync_fn: fn@(f: t, Level) -> int, + } // fsync file after executing blk // FIXME (#2004) find better way to create resources within lifetime of @@ -1139,7 +1145,7 @@ pub mod fsync { pub fn FILE_res_sync(file: &FILERes, opt_level: Option, blk: fn(v: Res<*libc::FILE>)) { unsafe { - blk(move Res({ + blk(Res(Arg { val: file.f, opt_level: opt_level, fsync_fn: fn@(file: *libc::FILE, l: Level) -> int { unsafe { @@ -1153,7 +1159,7 @@ pub mod fsync { // fsync fd after executing blk pub fn fd_res_sync(fd: &FdRes, opt_level: Option, blk: fn(v: Res)) { - blk(move Res({ + blk(Res(Arg { val: fd.fd, opt_level: opt_level, fsync_fn: fn@(fd: fd_t, l: Level) -> int { return os::fsync_fd(fd, l) as int; @@ -1167,7 +1173,7 @@ pub mod fsync { // Call o.fsync after executing blk pub fn obj_sync(o: FSyncable, opt_level: Option, blk: fn(v: Res)) { - blk(Res({ + blk(Res(Arg { val: o, opt_level: opt_level, fsync_fn: fn@(o: FSyncable, l: Level) -> int { return o.fsync(l); diff --git a/src/libcore/iter-trait/dlist.rs b/src/libcore/iter-trait/dlist.rs index 754b8f8b72fc8..5b5f786bac7ff 100644 --- a/src/libcore/iter-trait/dlist.rs +++ b/src/libcore/iter-trait/dlist.rs @@ -10,12 +10,13 @@ mod inst { use dlist; + use dlist::DList; use managed; use option::{Option, Some}; use option; #[allow(non_camel_case_types)] - pub type IMPL_T = dlist::DList; + pub type IMPL_T = @DList; /** * Iterates through the current contents. @@ -36,11 +37,11 @@ mod inst { } if !nobe.linked || (!((nobe.prev.is_some() - || managed::ptr_eq(*self.hd.expect(~"headless dlist?"), - *nobe)) + || managed::ptr_eq(self.hd.expect(~"headless dlist?"), + nobe)) && (nobe.next.is_some() - || managed::ptr_eq(*self.tl.expect(~"tailless dlist?"), - *nobe)))) { + || managed::ptr_eq(self.tl.expect(~"tailless dlist?"), + nobe)))) { fail ~"Removing a dlist node during iteration is forbidden!" } link = nobe.next_link(); diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 6c7be8a2ae51e..0ef30668dbce1 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -132,7 +132,7 @@ pub struct BufferHeader { // thing along. } -pub fn BufferHeader() -> BufferHeader{ +pub fn BufferHeader() -> BufferHeader { BufferHeader { ref_count: 0 } @@ -140,10 +140,19 @@ pub fn BufferHeader() -> BufferHeader{ // This is for protocols to associate extra data to thread around. #[doc(hidden)] +#[cfg(stage0)] type Buffer = { header: BufferHeader, data: T, }; +#[doc(hidden)] +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +pub struct Buffer { + header: BufferHeader, + data: T, +} struct PacketHeader { mut state: State, @@ -201,10 +210,10 @@ impl PacketHeader { } #[doc(hidden)] -pub type Packet = { +pub struct Packet { header: PacketHeader, mut payload: Option, -}; +} #[doc(hidden)] pub trait HasBuffer { @@ -223,19 +232,39 @@ impl Packet: HasBuffer { #[doc(hidden)] pub fn mk_packet() -> Packet { - { + Packet { header: PacketHeader(), - mut payload: None + payload: None, } } #[doc(hidden)] +#[cfg(stage0)] fn unibuffer() -> ~Buffer> { let b = ~{ header: BufferHeader(), - data: { + data: Packet { header: PacketHeader(), - mut payload: None, + payload: None, + } + }; + + unsafe { + b.data.header.buffer = reinterpret_cast(&b); + } + move b +} + +#[doc(hidden)] +#[cfg(stage1)] +#[cfg(stage2)] +#[cfg(stage3)] +fn unibuffer() -> ~Buffer> { + let b = ~Buffer { + header: BufferHeader(), + data: Packet { + header: PacketHeader(), + payload: None, } }; @@ -1011,7 +1040,9 @@ pub trait Peekable { } #[doc(hidden)] -type Chan_ = { mut endp: Option> }; +struct Chan_ { + mut endp: Option>, +} /// An endpoint that can send many messages. pub enum Chan { @@ -1019,7 +1050,9 @@ pub enum Chan { } #[doc(hidden)] -type Port_ = { mut endp: Option> }; +struct Port_ { + mut endp: Option>, +} /// An endpoint that can receive many messages. pub enum Port { @@ -1034,7 +1067,7 @@ These allow sending or receiving an unlimited number of messages. pub fn stream() -> (Port, Chan) { let (c, s) = streamp::init(); - (Port_({ mut endp: Some(move s) }), Chan_({ mut endp: Some(move c) })) + (Port_(Port_ { endp: Some(s) }), Chan_(Chan_{ endp: Some(c) })) } impl Chan: GenericChan { diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index e2101e06bfab9..976c186912b37 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -42,7 +42,10 @@ pub trait Rng { } /// A value with a particular weight compared to other values -pub type Weighted = { weight: uint, item: T }; +pub struct Weighted { + weight: uint, + item: T, +} /// Extension methods for random number generators impl Rng { @@ -312,12 +315,12 @@ pub fn seeded_rng(seed: &~[u8]) -> Rng { } } -type XorShiftState = { +struct XorShiftState { mut x: u32, mut y: u32, mut z: u32, - mut w: u32 -}; + mut w: u32, +} impl XorShiftState: Rng { fn next() -> u32 { @@ -338,7 +341,7 @@ pub pure fn xorshift() -> Rng { } pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng { - {mut x: x, mut y: y, mut z: z, mut w: w} as Rng + XorShiftState { x: x, y: y, z: z, w: w } as Rng } @@ -492,21 +495,24 @@ pub mod tests { #[test] pub fn choose_weighted() { let r = rand::Rng(); - assert r.choose_weighted(~[{weight: 1u, item: 42}]) == 42; assert r.choose_weighted(~[ - {weight: 0u, item: 42}, - {weight: 1u, item: 43} + rand::Weighted { weight: 1u, item: 42 }, + ]) == 42; + assert r.choose_weighted(~[ + rand::Weighted { weight: 0u, item: 42 }, + rand::Weighted { weight: 1u, item: 43 }, ]) == 43; } #[test] pub fn choose_weighted_option() { let r = rand::Rng(); - assert r.choose_weighted_option(~[{weight: 1u, item: 42}]) == - Some(42); assert r.choose_weighted_option(~[ - {weight: 0u, item: 42}, - {weight: 1u, item: 43} + rand::Weighted { weight: 1u, item: 42 }, + ]) == Some(42); + assert r.choose_weighted_option(~[ + rand::Weighted { weight: 0u, item: 42 }, + rand::Weighted { weight: 1u, item: 43 }, ]) == Some(43); let v: Option = r.choose_weighted_option([]); assert v.is_none(); @@ -518,9 +524,9 @@ pub mod tests { let empty: ~[int] = ~[]; assert r.weighted_vec(~[]) == empty; assert r.weighted_vec(~[ - {weight: 0u, item: 3u}, - {weight: 1u, item: 2u}, - {weight: 2u, item: 1u} + rand::Weighted { weight: 0u, item: 3u }, + rand::Weighted { weight: 1u, item: 2u }, + rand::Weighted { weight: 2u, item: 1u }, ]) == ~[2u, 1u, 1u]; } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 54bce77d30885..8960d40b85a24 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -204,83 +204,86 @@ pub fn run_program(prog: &str, args: &[~str]) -> int { * A class with a field */ pub fn start_program(prog: &str, args: &[~str]) -> Program { + let pipe_input = os::pipe(); + let pipe_output = os::pipe(); + let pipe_err = os::pipe(); + let pid = + spawn_process(prog, args, &None, &None, + pipe_input.in, pipe_output.out, + pipe_err.out); + unsafe { - let pipe_input = os::pipe(); - let pipe_output = os::pipe(); - let pipe_err = os::pipe(); - let pid = - spawn_process(prog, args, &None, &None, - pipe_input.in, pipe_output.out, - pipe_err.out); + if pid == -1 as pid_t { fail; } + libc::close(pipe_input.in); + libc::close(pipe_output.out); + libc::close(pipe_err.out); + } - unsafe { - if pid == -1 as pid_t { fail; } - libc::close(pipe_input.in); - libc::close(pipe_output.out); - libc::close(pipe_err.out); - } + struct ProgRepr { + pid: pid_t, + mut in_fd: c_int, + out_file: *libc::FILE, + err_file: *libc::FILE, + mut finished: bool, + } - type ProgRepr = {pid: pid_t, - mut in_fd: c_int, - out_file: *libc::FILE, - err_file: *libc::FILE, - mut finished: bool}; - - fn close_repr_input(r: &ProgRepr) { - let invalid_fd = -1i32; - if r.in_fd != invalid_fd { - unsafe { - libc::close(r.in_fd); - } - r.in_fd = invalid_fd; - } - } - fn finish_repr(r: &ProgRepr) -> int { - if r.finished { return 0; } - r.finished = true; - close_repr_input(r); - return waitpid(r.pid); - } - fn destroy_repr(r: &ProgRepr) { + fn close_repr_input(r: &ProgRepr) { + let invalid_fd = -1i32; + if r.in_fd != invalid_fd { unsafe { - finish_repr(r); - libc::fclose(r.out_file); - libc::fclose(r.err_file); + libc::close(r.in_fd); } + r.in_fd = invalid_fd; } - struct ProgRes { - r: ProgRepr, - drop { destroy_repr(&self.r); } + } + fn finish_repr(r: &ProgRepr) -> int { + if r.finished { return 0; } + r.finished = true; + close_repr_input(r); + return waitpid(r.pid); + } + fn destroy_repr(r: &ProgRepr) { + unsafe { + finish_repr(r); + libc::fclose(r.out_file); + libc::fclose(r.err_file); } + } + struct ProgRes { + r: ProgRepr, + drop { destroy_repr(&self.r); } + } - fn ProgRes(r: ProgRepr) -> ProgRes { - ProgRes { - r: move r - } + fn ProgRes(r: ProgRepr) -> ProgRes { + ProgRes { + r: move r } + } - impl ProgRes: Program { - fn get_id() -> pid_t { return self.r.pid; } - fn input() -> io::Writer { - io::fd_writer(self.r.in_fd, false) - } - fn output() -> io::Reader { - io::FILE_reader(self.r.out_file, false) - } - fn err() -> io::Reader { - io::FILE_reader(self.r.err_file, false) - } - fn close_input() { close_repr_input(&self.r); } - fn finish() -> int { finish_repr(&self.r) } - fn destroy() { destroy_repr(&self.r); } + impl ProgRes: Program { + fn get_id() -> pid_t { return self.r.pid; } + fn input() -> io::Writer { + io::fd_writer(self.r.in_fd, false) + } + fn output() -> io::Reader { + io::FILE_reader(self.r.out_file, false) + } + fn err() -> io::Reader { + io::FILE_reader(self.r.err_file, false) } - let repr = {pid: pid, - mut in_fd: pipe_input.out, - out_file: os::fdopen(pipe_output.in), - err_file: os::fdopen(pipe_err.in), - mut finished: false}; - return ProgRes(move repr) as Program; + fn close_input() { close_repr_input(&self.r); } + fn finish() -> int { finish_repr(&self.r) } + fn destroy() { destroy_repr(&self.r); } } + let repr = ProgRepr { + pid: pid, + in_fd: pipe_input.out, + out_file: os::fdopen(pipe_output.in), + err_file: os::fdopen(pipe_err.in), + finished: false, + }; + + ProgRes(repr) as Program } fn read_all(rd: io::Reader) -> ~str { diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index a8de34baf9eea..a4d99bf5db4a6 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -168,10 +168,10 @@ impl SchedMode : cmp::Eq { * default these foreign stacks have unspecified size, but with this * option their size can be precisely specified. */ -pub type SchedOpts = { +pub struct SchedOpts { mode: SchedMode, - foreign_stack_size: Option -}; + foreign_stack_size: Option, +} /** * Task configuration options @@ -200,12 +200,12 @@ pub type SchedOpts = { * into foreign code that blocks. Without doing so in a different * scheduler other tasks will be impeded or even blocked indefinitely. */ -pub type TaskOpts = { +pub struct TaskOpts { linked: bool, supervised: bool, mut notify_chan: Option>, sched: Option, -}; +} /** * The task builder type. @@ -251,15 +251,15 @@ priv impl TaskBuilder { self.consumed = true; let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { - opts: { + opts: TaskOpts { linked: self.opts.linked, supervised: self.opts.supervised, - mut notify_chan: move notify_chan, + notify_chan: notify_chan, sched: self.opts.sched }, gen_body: self.gen_body, can_not_copy: None, - mut consumed: false + consumed: false } } } @@ -272,10 +272,10 @@ impl TaskBuilder { fn unlinked() -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { - opts: { + opts: TaskOpts { linked: false, supervised: self.opts.supervised, - mut notify_chan: move notify_chan, + notify_chan: notify_chan, sched: self.opts.sched }, can_not_copy: None, @@ -290,10 +290,10 @@ impl TaskBuilder { fn supervised() -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { - opts: { + opts: TaskOpts { linked: false, supervised: true, - mut notify_chan: move notify_chan, + notify_chan: notify_chan, sched: self.opts.sched }, can_not_copy: None, @@ -307,10 +307,10 @@ impl TaskBuilder { fn linked() -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { - opts: { + opts: TaskOpts { linked: true, supervised: false, - mut notify_chan: move notify_chan, + notify_chan: notify_chan, sched: self.opts.sched }, can_not_copy: None, @@ -352,10 +352,10 @@ impl TaskBuilder { // Reconfigure self to use a notify channel. TaskBuilder { - opts: { + opts: TaskOpts { linked: self.opts.linked, supervised: self.opts.supervised, - mut notify_chan: Some(move notify_pipe_ch), + notify_chan: Some(notify_pipe_ch), sched: self.opts.sched }, can_not_copy: None, @@ -366,11 +366,14 @@ impl TaskBuilder { fn sched_mode(mode: SchedMode) -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { - opts: { + opts: TaskOpts { linked: self.opts.linked, supervised: self.opts.supervised, - mut notify_chan: move notify_chan, - sched: Some({ mode: mode, foreign_stack_size: None}) + notify_chan: notify_chan, + sched: Some(SchedOpts { + mode: mode, + foreign_stack_size: None, + }) }, can_not_copy: None, .. self.consume() @@ -393,10 +396,10 @@ impl TaskBuilder { let prev_gen_body = self.gen_body; let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { - opts: { + opts: TaskOpts { linked: self.opts.linked, supervised: self.opts.supervised, - mut notify_chan: move notify_chan, + notify_chan: notify_chan, sched: self.opts.sched }, // tjc: I think this is the line that gets miscompiled @@ -424,10 +427,10 @@ impl TaskBuilder { fn spawn(f: fn~()) { let notify_chan = replace(&mut self.opts.notify_chan, None); let x = self.consume(); - let opts = { + let opts = TaskOpts { linked: x.opts.linked, supervised: x.opts.supervised, - mut notify_chan: move notify_chan, + notify_chan: notify_chan, sched: x.opts.sched }; spawn::spawn_raw(move opts, (x.gen_body)(move f)); @@ -482,10 +485,10 @@ pub fn default_task_opts() -> TaskOpts { * into the same scheduler, and do not post lifecycle notifications. */ - { + TaskOpts { linked: true, supervised: false, - mut notify_chan: None, + notify_chan: None, sched: None } } diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 15f6bd413e446..edeacb31e1d09 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -114,14 +114,14 @@ pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { } // One of these per group of linked-failure tasks. -type TaskGroupData = { +struct TaskGroupData { // All tasks which might kill this group. When this is empty, the group // can be "GC"ed (i.e., its link in the ancestor list can be removed). mut members: TaskSet, // All tasks unidirectionally supervised by (directly or transitively) // tasks in this group. mut descendants: TaskSet, -}; +} type TaskGroupArc = private::Exclusive>; type TaskGroupInner = &mut Option; @@ -138,7 +138,7 @@ pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { // taskgroup which was spawned-unlinked. Tasks from intermediate generations // have references to the middle of the list; when intermediate generations // die, their node in the list will be collected at a descendant's spawn-time. -type AncestorNode = { +struct AncestorNode { // Since the ancestor list is recursive, we end up with references to // exclusives within other exclusives. This is dangerous business (if // circular references arise, deadlock and memory leaks are imminent). @@ -150,7 +150,8 @@ type AncestorNode = { mut parent_group: Option, // Recursive rest of the list. mut ancestors: AncestorList, -}; +} + enum AncestorList = Option>; // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. @@ -450,11 +451,10 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) // Main task, doing first spawn ever. Lazily initialise here. let mut members = new_taskset(); taskset_insert(&mut members, spawner); - let tasks = - private::exclusive(Some({ - mut members: move members, - mut descendants: new_taskset() - })); + let tasks = private::exclusive(Some(TaskGroupData { + members: members, + descendants: new_taskset(), + })); // Main task/group has no ancestors, no notifier, etc. let group = @TCB(spawner, move tasks, AncestorList(None), true, None); @@ -475,9 +475,9 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) (move g, move a, spawner_group.is_main) } else { // Child is in a separate group from spawner. - let g = private::exclusive(Some({ - mut members: new_taskset(), - mut descendants: new_taskset() + let g = private::exclusive(Some(TaskGroupData { + members: new_taskset(), + descendants: new_taskset(), })); let a = if supervised { // Child's ancestors start with the spawner. @@ -495,10 +495,11 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) }; assert new_generation < uint::max_value; // Build a new node in the ancestor list. - AncestorList(Some(private::exclusive( - { generation: new_generation, - mut parent_group: Some(spawner_group.tasks.clone()), - mut ancestors: move old_ancestors }))) + AncestorList(Some(private::exclusive(AncestorNode { + generation: new_generation, + parent_group: Some(spawner_group.tasks.clone()), + ancestors: old_ancestors, + }))) } else { // Child has no ancestors. AncestorList(None) @@ -685,9 +686,9 @@ fn test_spawn_raw_simple() { #[test] #[ignore(cfg(windows))] fn test_spawn_raw_unsupervise() { - let opts = { + let opts = task::TaskOpts { linked: false, - mut notify_chan: None, + notify_chan: None, .. default_task_opts() }; do spawn_raw(move opts) { @@ -700,8 +701,8 @@ fn test_spawn_raw_unsupervise() { fn test_spawn_raw_notify_success() { let (notify_po, notify_ch) = pipes::stream(); - let opts = { - notify_chan: Some(move notify_ch), + let opts = task::TaskOpts { + notify_chan: Some(notify_ch), .. default_task_opts() }; do spawn_raw(move opts) { @@ -715,9 +716,9 @@ fn test_spawn_raw_notify_failure() { // New bindings for these let (notify_po, notify_ch) = pipes::stream(); - let opts = { + let opts = task::TaskOpts { linked: false, - notify_chan: Some(move notify_ch), + notify_chan: Some(notify_ch), .. default_task_opts() }; do spawn_raw(move opts) { diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 7d7e16e930ca4..ebfcfd3757739 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -2027,10 +2027,10 @@ pub mod raw { unboxed: UnboxedVecRepr } - pub type SliceRepr = { + pub struct SliceRepr { mut data: *u8, mut len: uint - }; + } /** * Sets the length of a vector diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index b2fc59a7f443a..96fce53dd63b4 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -287,7 +287,7 @@ fn get_lint_settings_level(settings: lint_settings, // This is kind of unfortunate. It should be somewhere else, or we should use // a persistent data structure... fn clone_lint_modes(modes: lint_modes) -> lint_modes { - smallintmap::SmallIntMap_(@{v: copy modes.v}) + smallintmap::SmallIntMap_(@smallintmap::SmallIntMap_ { v: copy modes.v }) } type ctxt_ = {dict: lint_dict, diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 7ac11ecc5cc50..eef84ae2422ee 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -68,7 +68,11 @@ const tydesc_drop_glue_index: size_t = 3 as size_t; // The way arena uses arrays is really deeply awful. The arrays are // allocated, and have capacities reserved, but the fill for the array // will always stay at 0. -type Chunk = {data: @[u8], mut fill: uint, is_pod: bool}; +struct Chunk { + data: @[u8], + mut fill: uint, + is_pod: bool, +} pub struct Arena { // The head is seperated out from the list as a unbenchmarked @@ -93,13 +97,19 @@ impl Arena : Drop { fn chunk(size: uint, is_pod: bool) -> Chunk { let mut v: @[const u8] = @[]; unsafe { at_vec::raw::reserve(&mut v, size); } - { data: unsafe { cast::transmute(v) }, mut fill: 0u, is_pod: is_pod } + Chunk { + data: unsafe { cast::transmute(v) }, + fill: 0u, + is_pod: is_pod, + } } pub fn arena_with_size(initial_size: uint) -> Arena { - return Arena {mut head: chunk(initial_size, false), - mut pod_head: chunk(initial_size, true), - mut chunks: @Nil}; + Arena { + head: chunk(initial_size, false), + pod_head: chunk(initial_size, true), + chunks: @Nil, + } } pub fn Arena() -> Arena { diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 71d8743a36154..b4217dfb39d4a 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -61,10 +61,12 @@ pub fn create() -> Deque { match (*elts).get_elt(i) { Some(move t) => t, _ => fail } } - type Repr = {mut nelts: uint, - mut lo: uint, - mut hi: uint, - elts: DVec>}; + struct Repr { + mut nelts: uint, + mut lo: uint, + mut hi: uint, + elts: DVec>, + } impl Repr: Deque { fn size() -> uint { return self.nelts; } @@ -119,15 +121,14 @@ pub fn create() -> Deque { } } - let repr: Repr = { - mut nelts: 0u, - mut lo: 0u, - mut hi: 0u, - elts: - dvec::from_vec( - vec::from_elem(initial_capacity, None)) + let repr: Repr = Repr { + nelts: 0u, + lo: 0u, + hi: 0u, + elts: dvec::from_vec(vec::from_elem(initial_capacity, None)), }; - (move repr) as Deque:: + + repr as Deque:: } #[cfg(test)] @@ -254,7 +255,11 @@ mod tests { Onepar(int), Twopar(int, int), Threepar(int, int, int), } - type RecCy = {x: int, y: int, t: Taggy}; + struct RecCy { + x: int, + y: int, + t: Taggy, + } impl Taggy : Eq { pure fn eq(&self, other: &Taggy) -> bool { @@ -335,10 +340,10 @@ mod tests { #[test] fn test_param_reccy() { - let reccy1: RecCy = {x: 1, y: 2, t: One(1)}; - let reccy2: RecCy = {x: 345, y: 2, t: Two(1, 2)}; - let reccy3: RecCy = {x: 1, y: 777, t: Three(1, 2, 3)}; - let reccy4: RecCy = {x: 19, y: 252, t: Two(17, 42)}; + let reccy1 = RecCy { x: 1, y: 2, t: One(1) }; + let reccy2 = RecCy { x: 345, y: 2, t: Two(1, 2) }; + let reccy3 = RecCy { x: 1, y: 777, t: Three(1, 2, 3) }; + let reccy4 = RecCy { x: 19, y: 252, t: Two(17, 42) }; test_parameterized::(reccy1, reccy2, reccy3, reccy4); } } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 4c05dd154cad6..3c890ef06541f 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -107,7 +107,11 @@ pub trait Map { } pub mod util { - pub type Rational = {num: int, den: int}; // : int::positive(*.den); + pub struct Rational { + // : int::positive(*.den); + num: int, + den: int, + } pub pure fn rational_leq(x: Rational, y: Rational) -> bool { // NB: Uses the fact that rationals have positive denominators WLOG: @@ -265,9 +269,11 @@ pub mod chained { // consider rehashing if more 3/4 full let nchains = vec::len(self.chains); - let load = {num: (self.count + 1u) as int, - den: nchains as int}; - if !util::rational_leq(load, {num:3, den:4}) { + let load = util::Rational { + num: (self.count + 1u) as int, + den: nchains as int, + }; + if !util::rational_leq(load, util::Rational {num:3, den:4}) { self.rehash(); } @@ -324,9 +330,11 @@ pub mod chained { // consider rehashing if more 3/4 full let nchains = vec::len(self.chains); - let load = {num: (self.count + 1u) as int, - den: nchains as int}; - if !util::rational_leq(load, {num:3, den:4}) { + let load = util::Rational { + num: (self.count + 1u) as int, + den: nchains as int, + }; + if !util::rational_leq(load, util::Rational {num:3, den:4}) { self.rehash(); } diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index d273138ed3db5..84c3b75564984 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -48,9 +48,9 @@ pub enum IpAddr { } /// Human-friendly feedback on why a parse_addr attempt failed -pub type ParseAddrErr = { - err_msg: ~str -}; +pub struct ParseAddrErr { + err_msg: ~str, +} /** * Convert a `IpAddr` to a str @@ -122,7 +122,7 @@ pub fn get_addr(node: &str, iotask: iotask) log(debug, fmt!("slice len %?", len)); let handle = create_uv_getaddrinfo_t(); let handle_ptr = ptr::addr_of(&handle); - let handle_data: GetAddrData = { + let handle_data = GetAddrData { output_ch: output_ch }; let handle_data_ptr = ptr::addr_of(&handle_data); @@ -187,7 +187,7 @@ pub mod v4 { } // the simple, old style numberic representation of // ipv4 - pub type Ipv4Rep = { a: u8, b: u8, c: u8, d:u8 }; + pub struct Ipv4Rep { a: u8, b: u8, c: u8, d: u8 } pub trait AsUnsafeU32 { unsafe fn as_u32() -> u32; @@ -207,14 +207,14 @@ pub mod v4 { } }); if parts.len() != 4 { - result::Err(fmt!("'%s' doesn't have 4 parts", ip)) - } - else if parts.contains(&256) { - result::Err(fmt!("invalid octal in addr '%s'", ip)) - } - else { - result::Ok({a: parts[0] as u8, b: parts[1] as u8, - c: parts[2] as u8, d: parts[3] as u8}) + Err(fmt!("'%s' doesn't have 4 parts", ip)) + } else if parts.contains(&256) { + Err(fmt!("invalid octal in addr '%s'", ip)) + } else { + Ok(Ipv4Rep { + a: parts[0] as u8, b: parts[1] as u8, + c: parts[2] as u8, d: parts[3] as u8, + }) } } pub fn try_parse_addr(ip: &str) -> result::Result { @@ -223,7 +223,7 @@ pub mod v4 { let ip_rep_result = parse_to_ipv4_rep(ip); if result::is_err(&ip_rep_result) { let err_str = result::get_err(&ip_rep_result); - return result::Err({err_msg: err_str}) + return result::Err(ParseAddrErr { err_msg: err_str }) } // ipv4_rep.as_u32 is unsafe :/ let input_is_inaddr_none = @@ -236,15 +236,16 @@ pub mod v4 { let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name); if result::is_err(&ref_ip_rep_result) { let err_str = result::get_err(&ref_ip_rep_result); - return result::Err({err_msg: err_str}) + return Err(ParseAddrErr { err_msg: err_str }) } + if result::get(&ref_ip_rep_result).as_u32() == INADDR_NONE && !input_is_inaddr_none { - return result::Err( - {err_msg: ~"uv_ip4_name produced invalid result."}) - } - else { - result::Ok(Ipv4(copy(new_addr))) + Err(ParseAddrErr { + err_msg: ~"uv_ip4_name produced invalid result.", + }) + } else { + Ok(Ipv4(copy(new_addr))) } } } @@ -289,19 +290,18 @@ pub mod v6 { // '::' appears to be uv_ip6_name() returns for bogus // parses.. if ip != &"::" && reparsed_name == ~"::" { - result::Err({err_msg:fmt!("failed to parse '%s'", - ip)}) + Err(ParseAddrErr { err_msg:fmt!("failed to parse '%s'", ip) }) } else { - result::Ok(Ipv6(new_addr)) + Ok(Ipv6(new_addr)) } } } } -type GetAddrData = { +struct GetAddrData { output_ch: oldcomm::Chan> -}; +} extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, res: *addrinfo) { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index aeb0c2cb6130d..aa5eec2b43ce2 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -83,10 +83,11 @@ pub fn TcpSocketBuf(data: @TcpBufferedSocketData) -> TcpSocketBuf { } /// Contains raw, string-based, error information returned from libuv -pub type TcpErrData = { +pub struct TcpErrData { err_name: ~str, - err_msg: ~str -}; + err_msg: ~str, +} + /// Details returned as part of a `result::err` result from `tcp::listen` pub enum TcpListenErrData { /** @@ -155,7 +156,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, let reader_po = oldcomm::Port::>(); let stream_handle_ptr = malloc_uv_tcp_t(); *(stream_handle_ptr as *mut uv::ll::uv_tcp_t) = uv::ll::tcp_t(); - let socket_data = @{ + let socket_data = @TcpSocketData { reader_po: reader_po, reader_ch: oldcomm::Chan(&reader_po), stream_handle_ptr: stream_handle_ptr, @@ -231,7 +232,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, // ip or somesuch let err_data = uv::ll::get_last_err_data(loop_ptr); oldcomm::send((*conn_data_ptr).result_ch, - ConnFailure(err_data.to_tcp_err())); + ConnFailure(err_data)); uv::ll::set_data_for_uv_handle(stream_handle_ptr, conn_data_ptr); uv::ll::close(stream_handle_ptr, @@ -243,7 +244,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint, // failure to create a tcp handle let err_data = uv::ll::get_last_err_data(loop_ptr); oldcomm::send((*conn_data_ptr).result_ch, - ConnFailure(err_data.to_tcp_err())); + ConnFailure(err_data)); } } } @@ -513,7 +514,7 @@ pub fn accept(new_conn: TcpNewConnection) let iotask = (*server_data_ptr).iotask; let stream_handle_ptr = malloc_uv_tcp_t(); *(stream_handle_ptr as *mut uv::ll::uv_tcp_t) = uv::ll::tcp_t(); - let client_socket_data = @{ + let client_socket_data = @TcpSocketData { reader_po: reader_po, reader_ch: oldcomm::Chan(&reader_po), stream_handle_ptr : stream_handle_ptr, @@ -785,7 +786,7 @@ fn listen_common(host_ip: ip::IpAddr, port: uint, backlog: uint, * A buffered wrapper that you can cast as an `io::reader` or `io::writer` */ pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf { - TcpSocketBuf(@{ sock: move sock, mut buf: ~[] }) + TcpSocketBuf(@TcpBufferedSocketData { sock: sock, buf: ~[] }) } /// Convenience methods extending `net::tcp::tcp_socket` @@ -979,7 +980,7 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint) match move read_result { None => { log(debug, ~"tcp::read: timed out.."); - let err_data = { + let err_data = TcpErrData { err_name: ~"TIMEOUT", err_msg: ~"req timed out" }; @@ -1020,9 +1021,10 @@ fn read_stop_common_impl(socket_data: *TcpSocketData) -> } } }; + match oldcomm::recv(stop_po) { - Some(ref err_data) => result::Err(err_data.to_tcp_err()), - None => result::Ok(()) + Some(move err_data) => Err(err_data), + None => Ok(()) } } } @@ -1108,8 +1110,8 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData, // ownership of everything to the I/O task and let it deal with the // aftermath, so we don't have to sit here blocking. match oldcomm::recv(result_po) { - TcpWriteSuccess => result::Ok(()), - TcpWriteError(ref err_data) => result::Err(err_data.to_tcp_err()) + TcpWriteSuccess => Ok(()), + TcpWriteError(move err_data) => Err(err_data) } } } @@ -1118,15 +1120,15 @@ enum TcpNewConnection { NewTcpConn(*uv::ll::uv_tcp_t) } -type TcpListenFcData = { +struct TcpListenFcData { server_stream_ptr: *uv::ll::uv_tcp_t, stream_closed_ch: oldcomm::Chan<()>, kill_ch: oldcomm::Chan>, on_connect_cb: fn~(*uv::ll::uv_tcp_t), iotask: IoTask, ipv6: bool, - mut active: bool -}; + mut active: bool, +} extern fn tcp_lfc_close_cb(handle: *uv::ll::uv_tcp_t) { unsafe { @@ -1191,7 +1193,7 @@ trait ToTcpErr { impl uv::ll::uv_err_data: ToTcpErr { fn to_tcp_err() -> TcpErrData { - { err_name: self.err_name, err_msg: self.err_msg } + TcpErrData { err_name: self.err_name, err_msg: self.err_msg } } } @@ -1244,9 +1246,9 @@ extern fn on_alloc_cb(handle: *libc::c_void, } } -type TcpSocketCloseData = { - closed_ch: oldcomm::Chan<()> -}; +struct TcpSocketCloseData { + closed_ch: oldcomm::Chan<()>, +} extern fn tcp_socket_dtor_close_cb(handle: *uv::ll::uv_tcp_t) { unsafe { @@ -1273,19 +1275,19 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t, let err_data = uv::ll::get_last_err_data(loop_ptr); log(debug, ~"failure to write"); oldcomm::send((*write_data_ptr).result_ch, - TcpWriteError(err_data)); + TcpWriteError(err_data.to_tcp_err())); } } } -type WriteReqData = { - result_ch: oldcomm::Chan -}; +struct WriteReqData { + result_ch: oldcomm::Chan, +} -type ConnectReqData = { +struct ConnectReqData { result_ch: oldcomm::Chan, - closed_signal_ch: oldcomm::Chan<()> -}; + closed_signal_ch: oldcomm::Chan<()>, +} extern fn stream_error_close_cb(handle: *uv::ll::uv_tcp_t) { unsafe { @@ -1337,20 +1339,20 @@ enum ConnAttempt { ConnFailure(uv::ll::uv_err_data) } -type TcpSocketData = { +struct TcpSocketData { reader_po: oldcomm::Port>, reader_ch: oldcomm::Chan>, stream_handle_ptr: *uv::ll::uv_tcp_t, connect_req: uv::ll::uv_connect_t, write_req: uv::ll::uv_write_t, ipv6: bool, - iotask: IoTask -}; + iotask: IoTask, +} -type TcpBufferedSocketData = { +struct TcpBufferedSocketData { sock: TcpSocket, - mut buf: ~[u8] -}; + mut buf: ~[u8], +} //#[cfg(test)] pub mod test { diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index c469824f48d7a..8c6d77c882838 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -595,12 +595,12 @@ pub mod node { * string can be shared between several ropes, e.g. for indexing * purposes. */ - pub type Leaf = { + pub struct Leaf { byte_offset: uint, - byte_len: uint, - char_len: uint, - content: @~str - }; + byte_len: uint, + char_len: uint, + content: @~str, + } /** * A node obtained from the concatenation of two other nodes @@ -619,14 +619,14 @@ pub mod node { * * Used for rebalancing and to allocate stacks for traversals. */ - pub type Concat = { + pub struct Concat { //FIXME (#2744): Perhaps a `vec` instead of `left`/`right` - left: @Node, - right: @Node, + left: @Node, + right: @Node, char_len: uint, byte_len: uint, - height: uint - }; + height: uint, + } pub enum Node { /// A leaf consisting in a `str` @@ -709,11 +709,12 @@ pub mod node { pub fn of_substr_unsafer(str: @~str, byte_start: uint, byte_len: uint, char_len: uint) -> @Node { assert(byte_start + byte_len <= str::len(*str)); - let candidate = @Leaf({ - byte_offset: byte_start, - byte_len: byte_len, - char_len: char_len, - content: str}); + let candidate = @Leaf(Leaf { + byte_offset: byte_start, + byte_len: byte_len, + char_len: char_len, + content: str, + }); if char_len <= hint_max_leaf_char_len { return candidate; } else { @@ -736,11 +737,11 @@ pub mod node { else { hint_max_leaf_char_len }; let chunk_byte_len = str::count_bytes(*str, offset, chunk_char_len); - nodes[i] = @Leaf({ + nodes[i] = @Leaf(Leaf { byte_offset: offset, - byte_len: chunk_byte_len, - char_len: chunk_char_len, - content: str + byte_len: chunk_byte_len, + char_len: chunk_char_len, + content: str, }); offset += chunk_byte_len; @@ -767,15 +768,15 @@ pub mod node { pub pure fn byte_len(node: @Node) -> uint { //FIXME (#2744): Could we do this without the pattern-matching? match (*node) { - Leaf(y) => return y.byte_len, - Concat(ref y) => return y.byte_len + Leaf(y) => y.byte_len, + Concat(ref y) => y.byte_len } } pub pure fn char_len(node: @Node) -> uint { match (*node) { - Leaf(y) => return y.char_len, - Concat(ref y) => return y.char_len + Leaf(y) => y.char_len, + Concat(ref y) => y.char_len } } @@ -867,15 +868,15 @@ pub mod node { pub fn flatten(node: @Node) -> @Node { unsafe { match (*node) { - Leaf(_) => return node, - Concat(ref x) => { - return @Leaf({ - byte_offset: 0u, - byte_len: x.byte_len, - char_len: x.char_len, - content: @serialize_node(node) - }) - } + Leaf(_) => node, + Concat(ref x) => { + @Leaf(Leaf { + byte_offset: 0u, + byte_len: x.byte_len, + char_len: x.char_len, + content: @serialize_node(node), + }) + } } } } @@ -943,10 +944,12 @@ pub mod node { node::Leaf(x) => { let char_len = str::count_chars(*x.content, byte_offset, byte_len); - return @Leaf({byte_offset: byte_offset, - byte_len: byte_len, - char_len: char_len, - content: x.content}); + return @Leaf(Leaf { + byte_offset: byte_offset, + byte_len: byte_len, + char_len: char_len, + content: x.content, + }); } node::Concat(ref x) => { let left_len: uint = node::byte_len(x.left); @@ -1007,10 +1010,12 @@ pub mod node { str::count_bytes(*x.content, 0u, char_offset); let byte_len = str::count_bytes(*x.content, byte_offset, char_len); - return @Leaf({byte_offset: byte_offset, - byte_len: byte_len, - char_len: char_len, - content: x.content}); + return @Leaf(Leaf { + byte_offset: byte_offset, + byte_len: byte_len, + char_len: char_len, + content: x.content, + }); } node::Concat(ref x) => { if char_offset == 0u && char_len == x.char_len {return node;} @@ -1040,18 +1045,19 @@ pub mod node { } pub fn concat2(left: @Node, right: @Node) -> @Node { - return @Concat({left : left, - right : right, - char_len: char_len(left) + char_len(right), - byte_len: byte_len(left) + byte_len(right), - height: uint::max(height(left), height(right)) + 1u - }) + @Concat(Concat { + left: left, + right: right, + char_len: char_len(left) + char_len(right), + byte_len: byte_len(left) + byte_len(right), + height: uint::max(height(left), height(right)) + 1u, + }) } pub pure fn height(node: @Node) -> uint { match (*node) { - Leaf(_) => return 0u, - Concat(ref x) => return x.height + Leaf(_) => 0u, + Concat(ref x) => x.height, } } @@ -1135,7 +1141,7 @@ pub mod node { loop { match *node { Leaf(x) => return str::char_at(*x.content, pos), - Concat({left, right, _}) => { + Concat(Concat {left, right, _}) => { let left_len = char_len(left); node = if left_len > pos { left } else { pos -= left_len; right }; @@ -1151,22 +1157,22 @@ pub mod node { use core::prelude::*; use core::vec; - pub type T = { - stack: ~[mut @Node], - mut stackpos: int - }; + pub struct T { + stack: ~[mut @Node], + mut stackpos: int, + } pub fn empty() -> T { let stack : ~[mut @Node] = ~[mut]; - return {stack: move stack, mut stackpos: -1} + T { stack: stack, stackpos: -1 } } pub fn start(node: @Node) -> T { let stack = vec::cast_to_mut( vec::from_elem(height(node)+1u, node)); - return { - stack: move stack, - mut stackpos: 0 + T { + stack: stack, + stackpos: 0, } } @@ -1196,25 +1202,25 @@ pub mod node { use core::prelude::*; use core::str; - pub type T = { + pub struct T { leaf_iterator: leaf_iterator::T, mut leaf: Option, - mut leaf_byte_pos: uint - }; + mut leaf_byte_pos: uint, + } pub fn start(node: @Node) -> T { - return { + T { leaf_iterator: leaf_iterator::start(node), - mut leaf: option::None, - mut leaf_byte_pos: 0u + leaf: option::None, + leaf_byte_pos: 0u, } } pub fn empty() -> T { - return { + T { leaf_iterator: leaf_iterator::empty(), - mut leaf: option::None, - mut leaf_byte_pos: 0u + leaf: option::None, + leaf_byte_pos: 0u, } } diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index 7a524eb79851d..51c209b1b5f47 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -284,7 +284,10 @@ mod tests { #[test] fn test() { unsafe { - type Test = {input: ~str, output: ~[u8]}; + struct Test { + input: ~str, + output: ~[u8], + } fn a_million_letter_a() -> ~str { let mut i = 0; @@ -297,47 +300,64 @@ mod tests { } // Test messages from FIPS 180-1 - let fips_180_1_tests: ~[Test] = - ~[{input: ~"abc", - output: - ~[0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, - 0x47u8, 0x06u8, 0x81u8, 0x6Au8, - 0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, - 0x78u8, 0x50u8, 0xC2u8, 0x6Cu8, - 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]}, - {input: - ~"abcdbcdecdefdefgefghfghighij" + - ~"hijkijkljklmklmnlmnomnopnopq", - output: - ~[0x84u8, 0x98u8, 0x3Eu8, 0x44u8, - 0x1Cu8, 0x3Bu8, 0xD2u8, 0x6Eu8, - 0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, - 0xF9u8, 0x51u8, 0x29u8, 0xE5u8, - 0xE5u8, 0x46u8, 0x70u8, 0xF1u8]}, - {input: a_million_letter_a(), - output: - ~[0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, - 0xD4u8, 0xC4u8, 0xDAu8, 0xA4u8, - 0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, - 0xDBu8, 0xADu8, 0x27u8, 0x31u8, - 0x65u8, 0x34u8, 0x01u8, 0x6Fu8]}]; + let fips_180_1_tests = ~[ + Test { + input: ~"abc", + output: ~[ + 0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, + 0x47u8, 0x06u8, 0x81u8, 0x6Au8, + 0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, + 0x78u8, 0x50u8, 0xC2u8, 0x6Cu8, + 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8, + ], + }, + Test { + input: + ~"abcdbcdecdefdefgefghfghighij" + + ~"hijkijkljklmklmnlmnomnopnopq", + output: ~[ + 0x84u8, 0x98u8, 0x3Eu8, 0x44u8, + 0x1Cu8, 0x3Bu8, 0xD2u8, 0x6Eu8, + 0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, + 0xF9u8, 0x51u8, 0x29u8, 0xE5u8, + 0xE5u8, 0x46u8, 0x70u8, 0xF1u8, + ], + }, + Test { + input: a_million_letter_a(), + output: ~[ + 0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, + 0xD4u8, 0xC4u8, 0xDAu8, 0xA4u8, + 0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, + 0xDBu8, 0xADu8, 0x27u8, 0x31u8, + 0x65u8, 0x34u8, 0x01u8, 0x6Fu8, + ], + }, + ]; // Examples from wikipedia - let wikipedia_tests: ~[Test] = - ~[{input: ~"The quick brown fox jumps over the lazy dog", - output: - ~[0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, - 0x7au8, 0x2du8, 0x28u8, 0xfcu8, - 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, - 0xbbu8, 0x76u8, 0xe7u8, 0x39u8, - 0x1bu8, 0x93u8, 0xebu8, 0x12u8]}, - {input: ~"The quick brown fox jumps over the lazy cog", - output: - ~[0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, - 0xd2u8, 0x5eu8, 0x1bu8, 0x3au8, - 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, - 0x0bu8, 0xd1u8, 0x7du8, 0x9bu8, - 0x10u8, 0x0du8, 0xb4u8, 0xb3u8]}]; + let wikipedia_tests = ~[ + Test { + input: ~"The quick brown fox jumps over the lazy dog", + output: ~[ + 0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, + 0x7au8, 0x2du8, 0x28u8, 0xfcu8, + 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, + 0xbbu8, 0x76u8, 0xe7u8, 0x39u8, + 0x1bu8, 0x93u8, 0xebu8, 0x12u8, + ], + }, + Test { + input: ~"The quick brown fox jumps over the lazy cog", + output: ~[ + 0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, + 0xd2u8, 0x5eu8, 0x1bu8, 0x3au8, + 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, + 0x0bu8, 0xd1u8, 0x7du8, 0x9bu8, + 0x10u8, 0x0du8, 0xb4u8, 0xb3u8, + ], + }, + ]; let tests = fips_180_1_tests + wikipedia_tests; fn check_vec_eq(v0: ~[u8], v1: ~[u8]) { assert (vec::len::(v0) == vec::len::(v1)); diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index dbcb0c6aeec6e..feabb678d6686 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -25,7 +25,9 @@ use core::prelude::*; // FIXME (#2347): Should not be @; there's a bug somewhere in rustc that // requires this to be. -type SmallIntMap_ = {v: DVec>}; +struct SmallIntMap_ { + v: DVec>, +} pub enum SmallIntMap { SmallIntMap_(@SmallIntMap_) @@ -34,7 +36,7 @@ pub enum SmallIntMap { /// Create a smallintmap pub fn mk() -> SmallIntMap { let v = DVec(); - return SmallIntMap_(@{v: move v}); + SmallIntMap_(@SmallIntMap_ { v: v } ) } /** diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 95523c1e5789f..7b94702f974b4 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -74,8 +74,11 @@ pub fn test_main(args: &[~str], tests: &[TestDesc]) { if !run_tests_console(&opts, tests) { fail ~"Some tests failed"; } } -pub type TestOpts = {filter: Option<~str>, run_ignored: bool, - logfile: Option<~str>}; +pub struct TestOpts { + filter: Option<~str>, + run_ignored: bool, + logfile: Option<~str>, +} type OptRes = Either; @@ -97,10 +100,13 @@ pub fn parse_opts(args: &[~str]) -> OptRes { let run_ignored = getopts::opt_present(&matches, ~"ignored"); let logfile = getopts::opt_maybe_str(&matches, ~"logfile"); - let test_opts = {filter: filter, run_ignored: run_ignored, - logfile: logfile}; + let test_opts = TestOpts { + filter: filter, + run_ignored: run_ignored, + logfile: logfile, + }; - return either::Left(test_opts); + either::Left(test_opts) } #[deriving_eq] @@ -396,7 +402,10 @@ pub fn filter_tests(opts: &TestOpts, move filtered } -type TestFuture = {test: TestDesc, wait: fn@() -> TestResult}; +struct TestFuture { + test: TestDesc, + wait: fn@() -> TestResult, +} pub fn run_test(test: TestDesc, monitor_ch: oldcomm::Chan) { if test.ignore { @@ -431,7 +440,7 @@ mod tests { #[legacy_exports]; use test::{TrFailed, TrIgnored, TrOk, filter_tests, parse_opts, TestDesc}; - use test::{run_test}; + use test::{TestOpts, run_test}; use core::either; use core::oldcomm; @@ -528,13 +537,26 @@ mod tests { // When we run ignored tests the test filter should filter out all the // unignored tests and flip the ignore flag on the rest to false - let opts = {filter: option::None, run_ignored: true, - logfile: option::None}; - let tests = - ~[TestDesc {name: ~"1", testfn: fn~() { }, - ignore: true, should_fail: false}, - TestDesc {name: ~"2", testfn: fn~() { }, - ignore: false, should_fail: false}]; + let opts = TestOpts { + filter: option::None, + run_ignored: true, + logfile: option::None, + }; + + let tests = ~[ + TestDesc { + name: ~"1", + testfn: fn~() { }, + ignore: true, + should_fail: false, + }, + TestDesc { + name: ~"2", + testfn: fn~() { }, + ignore: false, + should_fail: false, + }, + ]; let filtered = filter_tests(&opts, tests); assert (vec::len(filtered) == 1u); @@ -544,8 +566,11 @@ mod tests { #[test] fn sort_tests() { - let opts = {filter: option::None, run_ignored: false, - logfile: option::None}; + let opts = TestOpts { + filter: option::None, + run_ignored: false, + logfile: option::None, + }; let names = ~[~"sha1::test", ~"int::test_to_str", ~"int::test_pow", diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 612024013591f..731767d475faa 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -902,7 +902,6 @@ mod tests { use core::uint; use core::vec; - #[test] fn test_get_time() { const some_recent_date: i64 = 1325376000i64; // 2012-01-01T00:00:00Z const some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z @@ -926,7 +925,6 @@ mod tests { } } - #[test] fn test_precise_time() { let s0 = precise_time_s(); let ns1 = precise_time_ns(); @@ -944,7 +942,6 @@ mod tests { assert ns2 >= ns1; } - #[test] fn test_at_utc() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -966,7 +963,6 @@ mod tests { assert utc.tm_nsec == 54321_i32; } - #[test] fn test_at() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -995,7 +991,6 @@ mod tests { assert local.tm_nsec == 54321_i32; } - #[test] fn test_to_timespec() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1007,7 +1002,6 @@ mod tests { assert utc.to_local().to_timespec() == time; } - #[test] fn test_conversions() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1024,7 +1018,6 @@ mod tests { assert utc.to_local().to_utc() == utc; } - #[test] fn test_strptime() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1179,8 +1172,6 @@ mod tests { assert test(~"%", ~"%%"); } - #[test] - #[ignore(reason = "randomred")] fn test_ctime() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1195,8 +1186,6 @@ mod tests { assert local.ctime() == ~"Fri Feb 13 15:31:30 2009"; } - #[test] - #[ignore(reason = "randomred")] fn test_strftime() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1270,7 +1259,6 @@ mod tests { assert utc.rfc3339() == ~"2009-02-13T23:31:30Z"; } - #[test] fn test_timespec_eq_ord() { use core::cmp::{eq, ge, gt, le, lt, ne}; @@ -1303,4 +1291,20 @@ mod tests { assert gt(c, b); assert gt(d, c); } + + #[test] + fn run_tests() { + // The tests race on tzset. So instead of having many independent + // tests, we will just call the functions now. + test_get_time(); + test_precise_time(); + test_at_utc(); + test_at(); + test_to_timespec(); + test_conversions(); + test_strptime(); + test_ctime(); + test_strftime(); + test_timespec_eq_ord(); + } } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 667708cfb3fe9..0a3d64a02a4ea 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -111,7 +111,7 @@ fn run_loop(iotask_ch: Chan) { ll::async_init(loop_ptr, async_handle, wake_up_cb); // initialize our loop data and store it in the loop - let data: IoTaskLoopData = { + let data = IoTaskLoopData { async_handle: async_handle, msg_po: Port() }; @@ -134,10 +134,10 @@ fn run_loop(iotask_ch: Chan) { } // data that lives for the lifetime of the high-evel oo -type IoTaskLoopData = { +struct IoTaskLoopData { async_handle: *ll::uv_async_t, - msg_po: Port -}; + msg_po: Port, +} fn send_msg(iotask: IoTask, msg: IoTaskMsg) { unsafe { @@ -214,10 +214,10 @@ mod test { ll::close(handle, async_close_cb); } } - type AhData = { + struct AhData { iotask: IoTask, - exit_ch: oldcomm::Chan<()> - }; + exit_ch: oldcomm::Chan<()>, + } fn impl_uv_iotask_async(iotask: IoTask) { unsafe { let async_handle = ll::async_t(); diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 17b1194502831..5060ae1a72279 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -41,10 +41,10 @@ use core::str; use core::vec; // libuv struct mappings -pub type uv_ip4_addr = { +pub struct uv_ip4_addr { ip: ~[u8], - port: int -}; + port: int, +} pub type uv_ip6_addr = uv_ip4_addr; pub enum uv_handle_type { @@ -67,31 +67,31 @@ pub enum uv_handle_type { pub type handle_type = libc::c_uint; -pub type uv_handle_fields = { +pub struct uv_handle_fields { loop_handle: *libc::c_void, type_: handle_type, close_cb: *u8, mut data: *libc::c_void, -}; +} // unix size: 8 -pub type uv_err_t = { +pub struct uv_err_t { code: libc::c_int, sys_errno_: libc::c_int -}; +} // don't create one of these directly. instead, // count on it appearing in libuv callbacks or embedded // in other types as a pointer to be used in other // operations (so mostly treat it as opaque, once you // have it in this form..) -pub type uv_stream_t = { - fields: uv_handle_fields -}; +pub struct uv_stream_t { + fields: uv_handle_fields, +} // 64bit unix size: 272 #[cfg(unix)] -pub type uv_tcp_t = { +pub struct uv_tcp_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, @@ -101,24 +101,24 @@ pub type uv_tcp_t = { a20: *u8, a21: *u8, a22: *u8, a23: *u8, a24: *u8, a25: *u8, a26: *u8, a27: *u8, a28: *u8, - a30: uv_tcp_t_32bit_unix_riders -}; + a30: uv_tcp_t_32bit_unix_riders, +} // 32bit unix size: 328 (164) #[cfg(target_arch="x86_64")] -pub type uv_tcp_t_32bit_unix_riders = { - a29: *u8 -}; +pub struct uv_tcp_t_32bit_unix_riders { + a29: *u8, +} #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] -pub type uv_tcp_t_32bit_unix_riders = { +pub struct uv_tcp_t_32bit_unix_riders { a29: *u8, a30: *u8, a31: *u8, a32: *u8, a33: *u8, a34: *u8, - a35: *u8, a36: *u8 -}; + a35: *u8, a36: *u8, +} // 32bit win32 size: 240 (120) #[cfg(windows)] -pub type uv_tcp_t = { +pub struct uv_tcp_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, @@ -126,140 +126,140 @@ pub type uv_tcp_t = { a12: *u8, a13: *u8, a14: *u8, a15: *u8, a16: *u8, a17: *u8, a18: *u8, a19: *u8, a20: *u8, a21: *u8, a22: *u8, a23: *u8, - a24: *u8, a25: *u8 -}; + a24: *u8, a25: *u8, +} // unix size: 48 #[cfg(unix)] -pub type uv_connect_t = { +pub struct uv_connect_t { a00: *u8, a01: *u8, a02: *u8, a03: *u8, - a04: *u8, a05: *u8 -}; + a04: *u8, a05: *u8, +} // win32 size: 88 (44) #[cfg(windows)] -pub type uv_connect_t = { +pub struct uv_connect_t { a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, - a08: *u8, a09: *u8, a10: *u8 -}; + a08: *u8, a09: *u8, a10: *u8, +} // unix size: 16 -pub type uv_buf_t = { +pub struct uv_buf_t { base: *u8, - len: libc::size_t -}; + len: libc::size_t, +} // no gen stub method.. should create // it via uv::direct::buf_init() // unix size: 144 #[cfg(unix)] -pub type uv_write_t = { +pub struct uv_write_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, a08: *u8, a09: *u8, a10: *u8, a11: *u8, a12: *u8, - a14: uv_write_t_32bit_unix_riders -}; + a14: uv_write_t_32bit_unix_riders, +} #[cfg(target_arch="x86_64")] -pub type uv_write_t_32bit_unix_riders = { - a13: *u8 -}; +pub struct uv_write_t_32bit_unix_riders { + a13: *u8, +} #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] -pub type uv_write_t_32bit_unix_riders = { - a13: *u8, a14: *u8 -}; +pub struct uv_write_t_32bit_unix_riders { + a13: *u8, a14: *u8, +} // win32 size: 136 (68) #[cfg(windows)] -pub type uv_write_t = { +pub struct uv_write_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, a08: *u8, a09: *u8, a10: *u8, a11: *u8, - a12: *u8 -}; + a12: *u8, +} // 64bit unix size: 120 // 32bit unix size: 152 (76) #[cfg(unix)] -pub type uv_async_t = { +pub struct uv_async_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, a08: *u8, a09: *u8, - a11: uv_async_t_32bit_unix_riders -}; + a11: uv_async_t_32bit_unix_riders, +} #[cfg(target_arch="x86_64")] -pub type uv_async_t_32bit_unix_riders = { - a10: *u8 -}; +pub struct uv_async_t_32bit_unix_riders { + a10: *u8, +} #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] -pub type uv_async_t_32bit_unix_riders = { - a10: *u8, a11: *u8, a12: *u8, a13: *u8 -}; +pub struct uv_async_t_32bit_unix_riders { + a10: *u8, a11: *u8, a12: *u8, a13: *u8, +} // win32 size 132 (68) #[cfg(windows)] -pub type uv_async_t = { +pub struct uv_async_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, a08: *u8, a09: *u8, a10: *u8, a11: *u8, - a12: *u8 -}; + a12: *u8, +} // 64bit unix size: 128 // 32bit unix size: 84 #[cfg(unix)] -pub type uv_timer_t = { +pub struct uv_timer_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, a08: *u8, a09: *u8, - a11: uv_timer_t_32bit_unix_riders -}; + a11: uv_timer_t_32bit_unix_riders, +} #[cfg(target_arch="x86_64")] -pub type uv_timer_t_32bit_unix_riders = { - a10: *u8, a11: *u8 -}; +pub struct uv_timer_t_32bit_unix_riders { + a10: *u8, a11: *u8, +} #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] -pub type uv_timer_t_32bit_unix_riders = { +pub struct uv_timer_t_32bit_unix_riders { a10: *u8, a11: *u8, a12: *u8, a13: *u8, - a14: *u8, a15: *u8, a16: *u8 -}; + a14: *u8, a15: *u8, a16: *u8, +} // win32 size: 64 #[cfg(windows)] -pub type uv_timer_t = { +pub struct uv_timer_t { fields: uv_handle_fields, a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, - a08: *u8, a09: *u8, a10: *u8, a11: *u8 -}; + a08: *u8, a09: *u8, a10: *u8, a11: *u8, +} // unix size: 16 -pub type sockaddr_in = { +pub struct sockaddr_in { mut sin_family: u16, mut sin_port: u16, mut sin_addr: u32, // in_addr: this is an opaque, per-platform struct - mut sin_zero: (u8, u8, u8, u8, u8, u8, u8, u8) -}; + mut sin_zero: (u8, u8, u8, u8, u8, u8, u8, u8), +} // unix size: 28 .. FIXME #1645 // stuck with 32 becuse of rust padding structs? #[cfg(target_arch="x86_64")] -pub type sockaddr_in6 = { +pub struct sockaddr_in6 { a0: *u8, a1: *u8, - a2: *u8, a3: *u8 -}; + a2: *u8, a3: *u8, +} #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] -pub type sockaddr_in6 = { +pub struct sockaddr_in6 { a0: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8, - a6: *u8, a7: *u8 -}; + a6: *u8, a7: *u8, +} // unix size: 28 .. FIXME #1645 // stuck with 32 becuse of rust padding structs? @@ -267,25 +267,25 @@ pub type addr_in = addr_in_impl::addr_in; #[cfg(unix)] pub mod addr_in_impl { #[cfg(target_arch="x86_64")] - pub type addr_in = { + pub struct addr_in { a0: *u8, a1: *u8, - a2: *u8, a3: *u8 - }; + a2: *u8, a3: *u8, + } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] - pub type addr_in = { + pub struct addr_in { a0: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8, a6: *u8, a7: *u8, - }; + } } #[cfg(windows)] pub mod addr_in_impl { - pub type addr_in = { + pub struct addr_in { a0: *u8, a1: *u8, - a2: *u8, a3: *u8 - }; + a2: *u8, a3: *u8, + } } // unix size: 48, 32bit: 32 @@ -294,42 +294,60 @@ pub type addrinfo = addrinfo_impl::addrinfo; #[cfg(target_os="android")] pub mod addrinfo_impl { #[cfg(target_arch="x86_64")] - pub type addrinfo = { + pub struct addrinfo { a00: *u8, a01: *u8, a02: *u8, a03: *u8, - a04: *u8, a05: *u8 - }; + a04: *u8, a05: *u8, + } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] - pub type addrinfo = { + pub struct addrinfo { a00: *u8, a01: *u8, a02: *u8, a03: *u8, - a04: *u8, a05: *u8, a06: *u8, a07: *u8 - }; + a04: *u8, a05: *u8, a06: *u8, a07: *u8, + } } #[cfg(target_os="macos")] #[cfg(target_os="freebsd")] pub mod addrinfo_impl { - pub type addrinfo = { + pub struct addrinfo { a00: *u8, a01: *u8, a02: *u8, a03: *u8, - a04: *u8, a05: *u8 - }; + a04: *u8, a05: *u8, + } } #[cfg(windows)] pub mod addrinfo_impl { - pub type addrinfo = { + pub struct addrinfo { a00: *u8, a01: *u8, a02: *u8, a03: *u8, - a04: *u8, a05: *u8 - }; + a04: *u8, a05: *u8, + } } // unix size: 72 -pub type uv_getaddrinfo_t = { +pub struct uv_getaddrinfo_t { a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, - a06: *u8, a07: *u8, a08: *u8 -}; + a06: *u8, a07: *u8, a08: *u8, +} pub mod uv_ll_struct_stubgen { - use uv_ll::{uv_async_t, uv_connect_t, uv_getaddrinfo_t, uv_tcp_t}; - use uv_ll::{uv_timer_t, uv_write_t}; + use uv_ll::{ + uv_async_t, + uv_connect_t, + uv_getaddrinfo_t, + uv_handle_fields, + uv_tcp_t, + uv_timer_t, + uv_write_t, + }; + + #[cfg(target_os = "linux")] + #[cfg(target_os = "android")] + #[cfg(target_os = "macos")] + #[cfg(target_os = "freebsd")] + use uv_ll::{ + uv_async_t_32bit_unix_riders, + uv_tcp_t_32bit_unix_riders, + uv_timer_t_32bit_unix_riders, + uv_write_t_32bit_unix_riders, + }; use core::ptr; @@ -343,9 +361,12 @@ pub mod uv_ll_struct_stubgen { return gen_stub_arch(); #[cfg(target_arch="x86_64")] pub fn gen_stub_arch() -> uv_tcp_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_tcp_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, @@ -361,17 +382,18 @@ pub mod uv_ll_struct_stubgen { a24: 0 as *u8, a25: 0 as *u8, a26: 0 as *u8, a27: 0 as *u8, a28: 0 as *u8, - a30: { - a29: 0 as *u8 - } - }; + a30: uv_tcp_t_32bit_unix_riders { a29: 0 as *u8 }, + } } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] pub fn gen_stub_arch() -> uv_tcp_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_tcp_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, @@ -387,19 +409,22 @@ pub mod uv_ll_struct_stubgen { a24: 0 as *u8, a25: 0 as *u8, a26: 0 as *u8, a27: 0 as *u8, a28: 0 as *u8, - a30: { + a30: uv_tcp_t_32bit_unix_riders { a29: 0 as *u8, a30: 0 as *u8, a31: 0 as *u8, a32: 0 as *u8, a33: 0 as *u8, a34: 0 as *u8, - a35: 0 as *u8, a36: 0 as *u8 - } - }; + a35: 0 as *u8, a36: 0 as *u8, + }, + } } } #[cfg(windows)] pub fn gen_stub_os() -> uv_tcp_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_tcp_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, @@ -412,58 +437,62 @@ pub mod uv_ll_struct_stubgen { a19: 0 as *u8, a20: 0 as *u8, a21: 0 as *u8, a22: 0 as *u8, a23: 0 as *u8, - a24: 0 as *u8, a25: 0 as *u8 - }; + a24: 0 as *u8, a25: 0 as *u8, + } } } #[cfg(unix)] pub fn gen_stub_uv_connect_t() -> uv_connect_t { - return { + uv_connect_t { a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, - a04: 0 as *u8, a05: 0 as *u8 - }; + a04: 0 as *u8, a05: 0 as *u8, + } } #[cfg(windows)] pub fn gen_stub_uv_connect_t() -> uv_connect_t { - return { + uv_connect_t { a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, - a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8 - }; + a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8, + } } #[cfg(unix)] pub fn gen_stub_uv_async_t() -> uv_async_t { return gen_stub_arch(); #[cfg(target_arch = "x86_64")] pub fn gen_stub_arch() -> uv_async_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_async_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, - a11: { - a10: 0 as *u8 - } - }; + a11: uv_async_t_32bit_unix_riders { a10: 0 as *u8 }, + } } #[cfg(target_arch = "x86")] #[cfg(target_arch="arm")] pub fn gen_stub_arch() -> uv_async_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_async_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, - a11: { + a11: uv_async_t_32bit_unix_riders { a10: 0 as *u8, a11: 0 as *u8, a12: 0 as *u8, a13: 0 as *u8 } @@ -472,107 +501,133 @@ pub mod uv_ll_struct_stubgen { } #[cfg(windows)] pub fn gen_stub_uv_async_t() -> uv_async_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_async_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8, a11: 0 as *u8, - a12: 0 as *u8 - }; + a12: 0 as *u8, + } } #[cfg(unix)] pub fn gen_stub_uv_timer_t() -> uv_timer_t { return gen_stub_arch(); #[cfg(target_arch = "x86_64")] pub fn gen_stub_arch() -> uv_timer_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_timer_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, - a11: { + a11: uv_timer_t_32bit_unix_riders { a10: 0 as *u8, a11: 0 as *u8 - } - }; + }, + } } #[cfg(target_arch = "x86")] #[cfg(target_arch="arm")] pub fn gen_stub_arch() -> uv_timer_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_timer_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, - a11: { + a11: uv_timer_t_32bit_unix_riders { a10: 0 as *u8, a11: 0 as *u8, a12: 0 as *u8, a13: 0 as *u8, a14: 0 as *u8, a15: 0 as *u8, - a16: 0 as *u8 - } - }; + a16: 0 as *u8, + }, + } } } #[cfg(windows)] pub fn gen_stub_uv_timer_t() -> uv_timer_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_timer_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8, - a11: 0 as *u8 - }; + a11: 0 as *u8, + } } #[cfg(unix)] pub fn gen_stub_uv_write_t() -> uv_write_t { return gen_stub_arch(); #[cfg(target_arch="x86_64")] pub fn gen_stub_arch() -> uv_write_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_write_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8, a11: 0 as *u8, - a12: 0 as *u8, a14: { a13: 0 as *u8 } - }; + a12: 0 as *u8, + a14: uv_write_t_32bit_unix_riders { a13: 0 as *u8 }, + } } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] pub fn gen_stub_arch() -> uv_write_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_write_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8, a09: 0 as *u8, a10: 0 as *u8, a11: 0 as *u8, - a12: 0 as *u8, a14: { a13: 0 as *u8, a14: 0 as *u8 } + a12: 0 as *u8, + a14: uv_write_t_32bit_unix_riders { + a13: 0 as *u8, + a14: 0 as *u8, + } }; } } #[cfg(windows)] pub fn gen_stub_uv_write_t() -> uv_write_t { - return { fields: { loop_handle: ptr::null(), type_: 0u32, - close_cb: ptr::null(), - mut data: ptr::null() }, + uv_write_t { + fields: uv_handle_fields { + loop_handle: ptr::null(), type_: 0u32, + close_cb: ptr::null(), + data: ptr::null(), + }, a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, @@ -583,7 +638,7 @@ pub mod uv_ll_struct_stubgen { }; } pub fn gen_stub_uv_getaddrinfo_t() -> uv_getaddrinfo_t { - { + uv_getaddrinfo_t { a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8, a03: 0 as *u8, a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8, a07: 0 as *u8, a08: 0 as *u8 @@ -851,7 +906,7 @@ pub unsafe fn async_send(async_handle: *uv_async_t) { return rustrt::rust_uv_async_send(async_handle); } pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t { - let out_buf = { base: ptr::null(), len: 0 as libc::size_t }; + let out_buf = uv_buf_t { base: ptr::null(), len: 0 as libc::size_t }; let out_buf_ptr = ptr::addr_of(&out_buf); log(debug, fmt!("buf_init - input %u len %u out_buf: %u", input as uint, @@ -1043,13 +1098,13 @@ pub unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data { let err_ptr = ptr::addr_of(&err); let err_name = str::raw::from_c_str(err_name(err_ptr)); let err_msg = str::raw::from_c_str(strerror(err_ptr)); - { err_name: err_name, err_msg: err_msg } + uv_err_data { err_name: err_name, err_msg: err_msg } } -pub type uv_err_data = { +pub struct uv_err_data { err_name: ~str, - err_msg: ~str -}; + err_msg: ~str, +} pub unsafe fn is_ipv4_addrinfo(input: *addrinfo) -> bool { rustrt::rust_uv_is_ipv4_addrinfo(input) @@ -1090,11 +1145,11 @@ pub mod test { tcp_read_error } - type request_wrapper = { + struct request_wrapper { write_req: *uv_write_t, req_buf: *~[uv_buf_t], - read_chan: *oldcomm::Chan<~str> - }; + read_chan: *oldcomm::Chan<~str>, + } extern fn after_close_cb(handle: *libc::c_void) { log(debug, fmt!("after uv_close! handle ptr: %?", @@ -1424,18 +1479,18 @@ pub mod test { } } - type tcp_server_data = { + struct tcp_server_data { client: *uv_tcp_t, server: *uv_tcp_t, server_kill_msg: ~str, server_resp_buf: *~[uv_buf_t], server_chan: *oldcomm::Chan<~str>, - server_write_req: *uv_write_t - }; + server_write_req: *uv_write_t, + } - type async_handle_data = { - continue_chan: *oldcomm::Chan - }; + struct async_handle_data { + continue_chan: *oldcomm::Chan, + } extern fn async_close_cb(handle: *libc::c_void) { log(debug, fmt!("SERVER: closing async cb... h: %?", @@ -1489,7 +1544,7 @@ pub mod test { { continue_chan: continue_chan }; let async_data_ptr = ptr::addr_of(&async_data); - let server_data: tcp_server_data = { + let server_data = tcp_server_data { client: tcp_client_ptr, server: tcp_server_ptr, server_kill_msg: kill_server_msg, diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 470b6e540edd6..77f230311358e 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -130,20 +130,6 @@ fn expand_auto_encode( do vec::flat_map(in_items) |item| { if item.attrs.any(is_auto_encode) { match item.node { - ast::item_ty( - @ast::Ty {node: ast::ty_rec(ref fields), _}, - tps - ) => { - let ser_impl = mk_rec_ser_impl( - cx, - item.span, - item.ident, - (*fields), - tps - ); - - ~[filter_attrs(*item), ser_impl] - }, ast::item_struct(@ast::struct_def { fields, _}, tps) => { let ser_impl = mk_struct_ser_impl( cx, @@ -199,20 +185,6 @@ fn expand_auto_decode( do vec::flat_map(in_items) |item| { if item.attrs.any(is_auto_decode) { match item.node { - ast::item_ty( - @ast::Ty {node: ast::ty_rec(ref fields), _}, - tps - ) => { - let deser_impl = mk_rec_deser_impl( - cx, - item.span, - item.ident, - (*fields), - tps - ); - - ~[filter_attrs(*item), deser_impl] - }, ast::item_struct(@ast::struct_def { fields, _}, tps) => { let deser_impl = mk_struct_deser_impl( cx, @@ -693,67 +665,48 @@ fn mk_deser_method( } } -fn mk_rec_ser_impl( - cx: ext_ctxt, - span: span, - ident: ast::ident, - fields: ~[ast::ty_field], - tps: ~[ast::ty_param] -) -> @ast::item { - let fields = mk_ser_fields(cx, span, mk_rec_fields(fields)); - - // ast for `__s.emit_rec(|| $(fields))` - let body = cx.expr_call( - span, - cx.expr_field( - span, - cx.expr_var(span, ~"__s"), - cx.ident_of(~"emit_rec") - ), - ~[cx.lambda_stmts(span, fields)] - ); - - mk_ser_impl(cx, span, ident, tps, body) -} - -fn mk_rec_deser_impl( +fn mk_struct_ser_impl( cx: ext_ctxt, span: span, ident: ast::ident, - fields: ~[ast::ty_field], + fields: ~[@ast::struct_field], tps: ~[ast::ty_param] ) -> @ast::item { - let fields = mk_deser_fields(cx, span, mk_rec_fields(fields)); - - // ast for `read_rec(|| $(fields))` - let body = cx.expr_call( - span, - cx.expr_field( - span, - cx.expr_var(span, ~"__d"), - cx.ident_of(~"read_rec") - ), - ~[ - cx.lambda_expr( - cx.expr( + let fields = do mk_struct_fields(fields).mapi |idx, field| { + // ast for `|| self.$(name).encode(__s)` + let expr_lambda = cx.lambda_expr( + cx.expr_call( + span, + cx.expr_field( span, - ast::expr_rec(fields, None) - ) + cx.expr_field( + span, + cx.expr_var(span, ~"self"), + field.ident + ), + cx.ident_of(~"encode") + ), + ~[cx.expr_var(span, ~"__s")] ) - ] - ); - - mk_deser_impl(cx, span, ident, tps, body) -} + ); -fn mk_struct_ser_impl( - cx: ext_ctxt, - span: span, - ident: ast::ident, - fields: ~[@ast::struct_field], - tps: ~[ast::ty_param] -) -> @ast::item { - let fields = mk_ser_fields(cx, span, mk_struct_fields(fields)); + // ast for `__s.emit_field($(name), $(idx), $(expr_lambda))` + cx.stmt( + cx.expr_call( + span, + cx.expr_field( + span, + cx.expr_var(span, ~"__s"), + cx.ident_of(~"emit_field") + ), + ~[ + cx.lit_str(span, @cx.str_of(field.ident)), + cx.lit_uint(span, idx), + expr_lambda, + ] + ) + ) + }; // ast for `__s.emit_struct($(name), || $(fields))` let ser_body = cx.expr_call( @@ -780,7 +733,47 @@ fn mk_struct_deser_impl( fields: ~[@ast::struct_field], tps: ~[ast::ty_param] ) -> @ast::item { - let fields = mk_deser_fields(cx, span, mk_struct_fields(fields)); + let fields = do mk_struct_fields(fields).mapi |idx, field| { + // ast for `|| std::serialize::decode(__d)` + let expr_lambda = cx.lambda( + cx.expr_blk( + cx.expr_call( + span, + cx.expr_path_global(span, ~[ + cx.ident_of(~"std"), + cx.ident_of(~"serialize"), + cx.ident_of(~"Decodable"), + cx.ident_of(~"decode"), + ]), + ~[cx.expr_var(span, ~"__d")] + ) + ) + ); + + // ast for `__d.read_field($(name), $(idx), $(expr_lambda))` + let expr: @ast::expr = cx.expr_call( + span, + cx.expr_field( + span, + cx.expr_var(span, ~"__d"), + cx.ident_of(~"read_field") + ), + ~[ + cx.lit_str(span, @cx.str_of(field.ident)), + cx.lit_uint(span, idx), + expr_lambda, + ] + ); + + ast::spanned { + node: ast::field_ { + mutbl: field.mutbl, + ident: field.ident, + expr: expr, + }, + span: span, + } + }; // ast for `read_struct($(name), || $(fields))` let body = cx.expr_call( @@ -818,16 +811,6 @@ struct field { mutbl: ast::mutability, } -fn mk_rec_fields(fields: ~[ast::ty_field]) -> ~[field] { - do fields.map |field| { - field { - span: field.span, - ident: field.node.ident, - mutbl: field.node.mt.mutbl, - } - } -} - fn mk_struct_fields(fields: ~[@ast::struct_field]) -> ~[field] { do fields.map |field| { let (ident, mutbl) = match field.node.kind { @@ -847,96 +830,6 @@ fn mk_struct_fields(fields: ~[@ast::struct_field]) -> ~[field] { } } -fn mk_ser_fields( - cx: ext_ctxt, - span: span, - fields: ~[field] -) -> ~[@ast::stmt] { - do fields.mapi |idx, field| { - // ast for `|| self.$(name).encode(__s)` - let expr_lambda = cx.lambda_expr( - cx.expr_call( - span, - cx.expr_field( - span, - cx.expr_field( - span, - cx.expr_var(span, ~"self"), - field.ident - ), - cx.ident_of(~"encode") - ), - ~[cx.expr_var(span, ~"__s")] - ) - ); - - // ast for `__s.emit_field($(name), $(idx), $(expr_lambda))` - cx.stmt( - cx.expr_call( - span, - cx.expr_field( - span, - cx.expr_var(span, ~"__s"), - cx.ident_of(~"emit_field") - ), - ~[ - cx.lit_str(span, @cx.str_of(field.ident)), - cx.lit_uint(span, idx), - expr_lambda, - ] - ) - ) - } -} - -fn mk_deser_fields( - cx: ext_ctxt, - span: span, - fields: ~[field] -) -> ~[ast::field] { - do fields.mapi |idx, field| { - // ast for `|| std::serialize::decode(__d)` - let expr_lambda = cx.lambda( - cx.expr_blk( - cx.expr_call( - span, - cx.expr_path_global(span, ~[ - cx.ident_of(~"std"), - cx.ident_of(~"serialize"), - cx.ident_of(~"Decodable"), - cx.ident_of(~"decode"), - ]), - ~[cx.expr_var(span, ~"__d")] - ) - ) - ); - - // ast for `__d.read_field($(name), $(idx), $(expr_lambda))` - let expr: @ast::expr = cx.expr_call( - span, - cx.expr_field( - span, - cx.expr_var(span, ~"__d"), - cx.ident_of(~"read_field") - ), - ~[ - cx.lit_str(span, @cx.str_of(field.ident)), - cx.lit_uint(span, idx), - expr_lambda, - ] - ); - - ast::spanned { - node: ast::field_ { - mutbl: field.mutbl, - ident: field.ident, - expr: expr, - }, - span: span, - } - } -} - fn mk_enum_ser_impl( cx: ext_ctxt, span: span, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 5e3d88b8b7fcf..5a8a1d8753dee 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -172,6 +172,15 @@ fn mk_struct_e(cx: ext_ctxt, sp: span, mk_fields(sp, fields), option::None::<@ast::expr>)) } +fn mk_global_struct_e(cx: ext_ctxt, sp: span, + ctor_path: ~[ast::ident], + fields: ~[{ident: ast::ident, ex: @ast::expr}]) -> + @ast::expr { + mk_expr(cx, sp, + ast::expr_struct(mk_raw_path_global(sp, ctor_path), + mk_fields(sp, fields), + option::None::<@ast::expr>)) +} fn mk_glob_use(cx: ext_ctxt, sp: span, path: ~[ast::ident]) -> @ast::view_item { let glob = @ast::spanned { diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 2b7bd9ddf32db..65890351e39fb 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -56,8 +56,8 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: ~[Piece], args: ~[@ast::expr]) -> @ast::expr { - fn make_path_vec(_cx: ext_ctxt, ident: @~str) -> ~[ast::ident] { - let intr = _cx.parse_sess().interner; + fn make_path_vec(cx: ext_ctxt, ident: @~str) -> ~[ast::ident] { + let intr = cx.parse_sess().interner; return ~[intr.intern(@~"extfmt"), intr.intern(@~"rt"), intr.intern(ident)]; } @@ -111,23 +111,28 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, } return make_rt_path_expr(cx, sp, @rt_type); } - fn make_conv_rec(cx: ext_ctxt, sp: span, flags_expr: @ast::expr, + fn make_conv_struct(cx: ext_ctxt, sp: span, flags_expr: @ast::expr, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { let intr = cx.parse_sess().interner; - return mk_rec_e(cx, sp, - ~[{ident: intr.intern(@~"flags"), ex: flags_expr}, - {ident: intr.intern(@~"width"), ex: width_expr}, - {ident: intr.intern(@~"precision"), - ex: precision_expr}, - {ident: intr.intern(@~"ty"), ex: ty_expr}]); + mk_global_struct_e( + cx, + sp, + make_path_vec(cx, @~"Conv"), + ~[ + {ident: intr.intern(@~"flags"), ex: flags_expr}, + {ident: intr.intern(@~"width"), ex: width_expr}, + {ident: intr.intern(@~"precision"), ex: precision_expr}, + {ident: intr.intern(@~"ty"), ex: ty_expr}, + ] + ) } let rt_conv_flags = make_flags(cx, sp, cnv.flags); let rt_conv_width = make_count(cx, sp, cnv.width); let rt_conv_precision = make_count(cx, sp, cnv.precision); let rt_conv_ty = make_ty(cx, sp, cnv.ty); - return make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width, - rt_conv_precision, rt_conv_ty); + make_conv_struct(cx, sp, rt_conv_flags, rt_conv_width, + rt_conv_precision, rt_conv_ty) } fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: ~str, cnv: Conv, arg: @ast::expr) -> @ast::expr { diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 6c12736b7eab6..e53057cb312e3 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -357,10 +357,10 @@ impl protocol: gen_init { fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr { debug!("gen_init_bounded"); let buffer_fields = self.gen_buffer_init(ext_cx); - let buffer = quote_expr!( - ~{header: ::pipes::BufferHeader(), - data: $buffer_fields} - ); + let buffer = quote_expr!(~::pipes::Buffer { + header: ::pipes::BufferHeader(), + data: $buffer_fields, + }); let entangle_body = ext_cx.block_expr( ext_cx.block( diff --git a/src/test/run-pass/auto-encode.rs b/src/test/run-pass/auto-encode.rs index 2bd00ddc4ef14..6ea08d200e77d 100644 --- a/src/test/run-pass/auto-encode.rs +++ b/src/test/run-pass/auto-encode.rs @@ -123,29 +123,33 @@ impl CLike : cmp::Eq { pure fn eq(&self, other: &CLike) -> bool { (*self) as int == *other as int } - pure fn ne(&self, other: &CLike) -> bool { !(*self).eq(other) } + pure fn ne(&self, other: &CLike) -> bool { !self.eq(other) } } #[auto_encode] #[auto_decode] -type Spanned = {lo: uint, hi: uint, node: T}; +struct Spanned { + lo: uint, + hi: uint, + node: T, +} impl Spanned : cmp::Eq { pure fn eq(&self, other: &Spanned) -> bool { - (*self).lo == other.lo && - (*self).hi == other.hi && - (*self).node == other.node + self.lo == other.lo && + self.hi == other.hi && + self.node == other.node } - pure fn ne(&self, other: &Spanned) -> bool { !(*self).eq(other) } + pure fn ne(&self, other: &Spanned) -> bool { !self.eq(other) } } #[auto_encode] #[auto_decode] -type SomeRec = {v: ~[uint]}; +struct SomeStruct { v: ~[uint] } #[auto_encode] #[auto_decode] -enum AnEnum = SomeRec; +enum AnEnum = SomeStruct; #[auto_encode] #[auto_decode] @@ -168,12 +172,12 @@ fn main() { @Plus(@Val(22u), @Val(5u)))"); test_ebml(a); - let a = &{lo: 0u, hi: 5u, node: 22u}; - test_prettyprint(a, &~"{lo: 0u, hi: 5u, node: 22u}"); + let a = &Spanned {lo: 0u, hi: 5u, node: 22u}; + test_prettyprint(a, &~"Spanned {lo: 0u, hi: 5u, node: 22u}"); test_ebml(a); - let a = &AnEnum({v: ~[1u, 2u, 3u]}); - test_prettyprint(a, &~"AnEnum({v: ~[1u, 2u, 3u]})"); + let a = &AnEnum(SomeStruct {v: ~[1u, 2u, 3u]}); + test_prettyprint(a, &~"AnEnum(SomeStruct {v: ~[1u, 2u, 3u]})"); test_ebml(a); let a = &Point {x: 3u, y: 5u}; diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 774e3544d891d..f44c54d38e4d9 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -27,7 +27,7 @@ mod pingpong { }; pub fn init() -> (client::ping, server::ping) { - let buffer = ~{ + let buffer = ~Buffer { header: BufferHeader(), data: { ping: mk_packet::(),