diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-05-05 18:56:44 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-05-06 23:12:54 -0700 |
| commit | 090040bf4037a094e50b03d79e4baf5cd89c912b (patch) | |
| tree | 27fa91d623889d59260d3db167abdfa8c4288849 /src/libstd | |
| parent | 24f6f26e633e50b5b59f9d0f6cca0b1e49e215d9 (diff) | |
| download | rust-090040bf4037a094e50b03d79e4baf5cd89c912b.tar.gz rust-090040bf4037a094e50b03d79e4baf5cd89c912b.zip | |
librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, except
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
Diffstat (limited to 'src/libstd')
56 files changed, 356 insertions, 291 deletions
diff --git a/src/libstd/any.rs b/src/libstd/any.rs index e448b7b8e24..2c1ce9fa779 100644 --- a/src/libstd/any.rs +++ b/src/libstd/any.rs @@ -17,12 +17,13 @@ //! As `&Any` (a borrowed trait object), it has the `is` and `as_ref` methods, to test if the //! contained value is of a given type, and to get a reference to the inner value as a type. As //! `&mut Any`, there is also the `as_mut` method, for getting a mutable reference to the inner -//! value. `~Any` adds the `move` method, which will unwrap a `~T` from the object. See the -//! extension traits (`*Ext`) for the full details. +//! value. `Box<Any>` adds the `move` method, which will unwrap a `Box<T>` from the object. See +//! the extension traits (`*Ext`) for the full details. use cast::{transmute, transmute_copy}; use fmt; use option::{Option, Some, None}; +use owned::Box; use raw::TraitObject; use result::{Result, Ok, Err}; use intrinsics::TypeId; @@ -121,12 +122,12 @@ impl<'a> AnyMutRefExt<'a> for &'a mut Any { pub trait AnyOwnExt { /// Returns the boxed value if it is of type `T`, or /// `Err(Self)` if it isn't. - fn move<T: 'static>(self) -> Result<~T, Self>; + fn move<T: 'static>(self) -> Result<Box<T>, Self>; } -impl AnyOwnExt for ~Any { +impl AnyOwnExt for Box<Any> { #[inline] - fn move<T: 'static>(self) -> Result<~T, ~Any> { + fn move<T: 'static>(self) -> Result<Box<T>, Box<Any>> { if self.is::<T>() { unsafe { // Get the raw representation of the trait object @@ -148,9 +149,9 @@ impl AnyOwnExt for ~Any { // Trait implementations /////////////////////////////////////////////////////////////////////////////// -impl fmt::Show for ~Any { +impl fmt::Show for Box<Any> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.pad("~Any") + f.pad("Box<Any>") } } @@ -164,6 +165,7 @@ impl<'a> fmt::Show for &'a Any { mod tests { use prelude::*; use super::*; + use owned::Box; use str::StrSlice; #[deriving(Eq, Show)] @@ -190,7 +192,7 @@ mod tests { #[test] fn any_owning() { - let (a, b, c) = (box 5u as ~Any, box TEST as ~Any, box Test as ~Any); + let (a, b, c) = (box 5u as Box<Any>, box TEST as Box<Any>, box Test as Box<Any>); assert!(a.is::<uint>()); assert!(!b.is::<uint>()); @@ -268,8 +270,8 @@ mod tests { #[test] fn any_move() { - let a = box 8u as ~Any; - let b = box Test as ~Any; + let a = box 8u as Box<Any>; + let b = box Test as Box<Any>; match a.move::<uint>() { Ok(a) => { assert_eq!(a, box 8u); } @@ -280,19 +282,19 @@ mod tests { Err(..) => fail!() } - let a = box 8u as ~Any; - let b = box Test as ~Any; + let a = box 8u as Box<Any>; + let b = box Test as Box<Any>; - assert!(a.move::<~Test>().is_err()); - assert!(b.move::<~uint>().is_err()); + assert!(a.move::<Box<Test>>().is_err()); + assert!(b.move::<Box<uint>>().is_err()); } #[test] fn test_show() { - let a = box 8u as ~Any; - let b = box Test as ~Any; - assert_eq!(format!("{}", a), "~Any".to_owned()); - assert_eq!(format!("{}", b), "~Any".to_owned()); + let a = box 8u as Box<Any>; + let b = box Test as Box<Any>; + assert_eq!(format!("{}", a), "Box<Any>".to_owned()); + assert_eq!(format!("{}", b), "Box<Any>".to_owned()); let a = &8u as &Any; let b = &Test as &Any; diff --git a/src/libstd/clone.rs b/src/libstd/clone.rs index e25f9c5ad4f..36d1cd9ba94 100644 --- a/src/libstd/clone.rs +++ b/src/libstd/clone.rs @@ -21,6 +21,8 @@ the `clone` method. */ +use owned::Box; + /// A common trait for cloning an object. pub trait Clone { /// Returns a copy of the value. The contents of owned pointers @@ -39,14 +41,14 @@ pub trait Clone { } } -impl<T: Clone> Clone for ~T { +impl<T: Clone> Clone for Box<T> { /// Return a copy of the owned box. #[inline] - fn clone(&self) -> ~T { box {(**self).clone()} } + fn clone(&self) -> Box<T> { box {(**self).clone()} } /// Perform copy-assignment from `source` by reusing the existing allocation. #[inline] - fn clone_from(&mut self, source: &~T) { + fn clone_from(&mut self, source: &Box<T>) { (**self).clone_from(&(**source)); } } @@ -127,7 +129,7 @@ extern_fn_clone!(A, B, C, D, E, F, G, H) #[test] fn test_owned_clone() { let a = box 5i; - let b: ~int = a.clone(); + let b: Box<int> = a.clone(); assert_eq!(a, b); } diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs index c7849892465..bd1def518f0 100644 --- a/src/libstd/comm/mod.rs +++ b/src/libstd/comm/mod.rs @@ -279,6 +279,7 @@ use kinds::marker; use mem; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use result::{Ok, Err, Result}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -297,6 +298,7 @@ macro_rules! test ( use prelude::*; use super::*; use super::super::*; + use owned::Box; use task; fn f() $b @@ -549,7 +551,7 @@ impl<T: Send> Sender<T> { let cnt = self.sends.get() + 1; self.sends.set(cnt); if cnt % (RESCHED_FREQ as uint) == 0 { - let task: Option<~Task> = Local::try_take(); + let task: Option<Box<Task>> = Local::try_take(); task.map(|t| t.maybe_yield()); } @@ -773,7 +775,7 @@ impl<T: Send> Receiver<T> { let cnt = self.receives.get() + 1; self.receives.set(cnt); if cnt % (RESCHED_FREQ as uint) == 0 { - let task: Option<~Task> = Local::try_take(); + let task: Option<Box<Task>> = Local::try_take(); task.map(|t| t.maybe_yield()); } @@ -979,6 +981,7 @@ mod test { use native; use os; + use owned::Box; use super::*; pub fn stress_factor() -> uint { @@ -1197,7 +1200,7 @@ mod test { test!(fn oneshot_single_thread_send_port_close() { // Testing that the sender cleans up the payload if receiver is closed - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::<Box<int>>(); drop(rx); tx.send(box 0); } #[should_fail]) @@ -1214,7 +1217,7 @@ mod test { }) test!(fn oneshot_single_thread_send_then_recv() { - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::<Box<int>>(); tx.send(box 10); assert!(rx.recv() == box 10); }) @@ -1263,7 +1266,7 @@ mod test { }) test!(fn oneshot_multi_task_recv_then_send() { - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::<Box<int>>(); spawn(proc() { assert!(rx.recv() == box 10); }); @@ -1272,7 +1275,7 @@ mod test { }) test!(fn oneshot_multi_task_recv_then_close() { - let (tx, rx) = channel::<~int>(); + let (tx, rx) = channel::<Box<int>>(); spawn(proc() { drop(tx); }); @@ -1340,7 +1343,7 @@ mod test { send(tx, 0); recv(rx, 0); - fn send(tx: Sender<~int>, i: int) { + fn send(tx: Sender<Box<int>>, i: int) { if i == 10 { return } spawn(proc() { @@ -1349,7 +1352,7 @@ mod test { }); } - fn recv(rx: Receiver<~int>, i: int) { + fn recv(rx: Receiver<Box<int>>, i: int) { if i == 10 { return } spawn(proc() { @@ -1513,6 +1516,7 @@ mod test { mod sync_tests { use prelude::*; use os; + use owned::Box; pub fn stress_factor() -> uint { match os::getenv("RUST_TEST_STRESS") { @@ -1657,7 +1661,7 @@ mod sync_tests { test!(fn oneshot_single_thread_send_port_close() { // Testing that the sender cleans up the payload if receiver is closed - let (tx, rx) = sync_channel::<~int>(0); + let (tx, rx) = sync_channel::<Box<int>>(0); drop(rx); tx.send(box 0); } #[should_fail]) @@ -1674,7 +1678,7 @@ mod sync_tests { }) test!(fn oneshot_single_thread_send_then_recv() { - let (tx, rx) = sync_channel::<~int>(1); + let (tx, rx) = sync_channel::<Box<int>>(1); tx.send(box 10); assert!(rx.recv() == box 10); }) @@ -1728,7 +1732,7 @@ mod sync_tests { }) test!(fn oneshot_multi_task_recv_then_send() { - let (tx, rx) = sync_channel::<~int>(0); + let (tx, rx) = sync_channel::<Box<int>>(0); spawn(proc() { assert!(rx.recv() == box 10); }); @@ -1737,7 +1741,7 @@ mod sync_tests { }) test!(fn oneshot_multi_task_recv_then_close() { - let (tx, rx) = sync_channel::<~int>(0); + let (tx, rx) = sync_channel::<Box<int>>(0); spawn(proc() { drop(tx); }); @@ -1805,7 +1809,7 @@ mod sync_tests { send(tx, 0); recv(rx, 0); - fn send(tx: SyncSender<~int>, i: int) { + fn send(tx: SyncSender<Box<int>>, i: int) { if i == 10 { return } spawn(proc() { @@ -1814,7 +1818,7 @@ mod sync_tests { }); } - fn recv(rx: Receiver<~int>, i: int) { + fn recv(rx: Receiver<Box<int>>, i: int) { if i == 10 { return } spawn(proc() { diff --git a/src/libstd/comm/oneshot.rs b/src/libstd/comm/oneshot.rs index e92b5cb272a..a7124e50b66 100644 --- a/src/libstd/comm/oneshot.rs +++ b/src/libstd/comm/oneshot.rs @@ -37,6 +37,7 @@ use kinds::Send; use mem; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use result::{Result, Ok, Err}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -137,7 +138,7 @@ impl<T: Send> Packet<T> { // Attempt to not block the task (it's a little expensive). If it looks // like we're not empty, then immediately go through to `try_recv`. if self.state.load(atomics::SeqCst) == EMPTY { - let t: ~Task = Local::take(); + let t: Box<Task> = Local::take(); t.deschedule(1, |task| { let n = unsafe { task.cast_to_uint() }; match self.state.compare_and_swap(EMPTY, n, atomics::SeqCst) { diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs index c286fd84849..cebfeb5399e 100644 --- a/src/libstd/comm/select.rs +++ b/src/libstd/comm/select.rs @@ -52,6 +52,7 @@ use kinds::marker; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use ptr::RawPtr; use result::{Ok, Err, Result}; use rt::local::Local; @@ -176,7 +177,7 @@ impl Select { // Acquire a number of blocking contexts, and block on each one // sequentially until one fails. If one fails, then abort // immediately so we can go unblock on all the other receivers. - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); task.deschedule(amt, |task| { // Prepare for the block let (i, handle) = iter.next().unwrap(); diff --git a/src/libstd/comm/shared.rs b/src/libstd/comm/shared.rs index c0f1aeae26b..8aef2ec80a8 100644 --- a/src/libstd/comm/shared.rs +++ b/src/libstd/comm/shared.rs @@ -24,6 +24,7 @@ use iter::Iterator; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use result::{Ok, Err, Result}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -223,7 +224,7 @@ impl<T: Send> Packet<T> { data => return data, } - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); task.deschedule(1, |task| { self.decrement(task) }); diff --git a/src/libstd/comm/stream.rs b/src/libstd/comm/stream.rs index 44070dc4460..9fb22ef4508 100644 --- a/src/libstd/comm/stream.rs +++ b/src/libstd/comm/stream.rs @@ -24,6 +24,7 @@ use iter::Iterator; use kinds::Send; use ops::Drop; use option::{Some, None}; +use owned::Box; use result::{Ok, Err, Result}; use rt::local::Local; use rt::task::{Task, BlockedTask}; @@ -181,7 +182,7 @@ impl<T: Send> Packet<T> { // Welp, our channel has no data. Deschedule the current task and // initiate the blocking protocol. - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); task.deschedule(1, |task| { self.decrement(task) }); diff --git a/src/libstd/comm/sync.rs b/src/libstd/comm/sync.rs index 6228c4c682b..db3f90cad5a 100644 --- a/src/libstd/comm/sync.rs +++ b/src/libstd/comm/sync.rs @@ -40,6 +40,7 @@ use kinds::Send; use mem; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use ptr::RawPtr; use result::{Result, Ok, Err}; use rt::local::Local; @@ -111,7 +112,7 @@ pub enum Failure { /// in the meantime. This re-locks the mutex upon returning. fn wait(slot: &mut Blocker, f: fn(BlockedTask) -> Blocker, lock: &NativeMutex) { - let me: ~Task = Local::take(); + let me: Box<Task> = Local::take(); me.deschedule(1, |task| { match mem::replace(slot, f(task)) { NoneBlocked => {} @@ -445,7 +446,7 @@ impl<T> Buffer<T> { impl Queue { fn enqueue(&mut self, lock: &NativeMutex) { - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); let mut node = Node { task: None, next: 0 as *mut Node, diff --git a/src/libstd/default.rs b/src/libstd/default.rs index 8dcce3fd146..9cf3a763648 100644 --- a/src/libstd/default.rs +++ b/src/libstd/default.rs @@ -10,6 +10,8 @@ //! The `Default` trait for types which may have meaningful default values +use owned::Box; + /// A trait that types which have a useful default value should implement. pub trait Default { /// Return the "default value" for a type. @@ -20,6 +22,6 @@ impl<T: Default + 'static> Default for @T { fn default() -> @T { @Default::default() } } -impl<T: Default> Default for ~T { - fn default() -> ~T { box Default::default() } +impl<T: Default> Default for Box<T> { + fn default() -> Box<T> { box Default::default() } } diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index e225dc42e05..38456e195e3 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -492,6 +492,7 @@ use io; use iter::{Iterator, range}; use num::Signed; use option::{Option,Some,None}; +use owned::Box; use repr; use result::{Ok, Err}; use str::StrSlice; @@ -1113,7 +1114,7 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> { impl<T: Show> Show for @T { fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) } } -impl<T: Show> Show for ~T { +impl<T: Show> Show for Box<T> { fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) } } impl<'a, T: Show> Show for &'a T { diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index 0ba8cff742b..ba126e00153 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -17,6 +17,7 @@ use prelude::*; use char; +use owned::Box; use str; /// A piece is a portion of the format string which represents the next part @@ -41,7 +42,7 @@ pub struct Argument<'a> { /// How to format the argument pub format: FormatSpec<'a>, /// If not `None`, what method to invoke on the argument - pub method: Option<~Method<'a>> + pub method: Option<Box<Method<'a>>> } /// Specification for the formatting of an argument in the format string. @@ -435,7 +436,7 @@ impl<'a> Parser<'a> { /// Parses a method to be applied to the previously specified argument and /// its format. The two current supported methods are 'plural' and 'select' - fn method(&mut self) -> Option<~Method<'a>> { + fn method(&mut self) -> Option<Box<Method<'a>>> { if !self.wsconsume(',') { return None; } @@ -461,7 +462,7 @@ impl<'a> Parser<'a> { } /// Parses a 'select' statement (after the initial 'select' word) - fn select(&mut self) -> ~Method<'a> { + fn select(&mut self) -> Box<Method<'a>> { let mut other = None; let mut arms = vec!(); // Consume arms one at a time @@ -503,7 +504,7 @@ impl<'a> Parser<'a> { } /// Parses a 'plural' statement (after the initial 'plural' word) - fn plural(&mut self) -> ~Method<'a> { + fn plural(&mut self) -> Box<Method<'a>> { let mut offset = None; let mut other = None; let mut arms = vec!(); diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index e8ca4037f57..748cf0eeed9 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -67,6 +67,7 @@ use container::Container; use io::Writer; use iter::Iterator; use option::{Option, Some, None}; +use owned::Box; use rc::Rc; use str::{Str, StrSlice}; use slice::{Vector, ImmutableVector}; @@ -229,7 +230,7 @@ impl<'a, S: Writer, T: Hash<S>> Hash<S> for &'a mut T { } } -impl<S: Writer, T: Hash<S>> Hash<S> for ~T { +impl<S: Writer, T: Hash<S>> Hash<S> for Box<T> { #[inline] fn hash(&self, state: &mut S) { (**self).hash(state); diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 6d48b9eee35..3f66ecd5db3 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -55,11 +55,12 @@ use container::Container; use iter::Iterator; use kinds::Send; use super::{Reader, Writer, Seek}; -use super::{SeekStyle, Read, Write, Open, IoError, Truncate, - FileMode, FileAccess, FileStat, IoResult, FilePermission}; +use super::{SeekStyle, Read, Write, Open, IoError, Truncate}; +use super::{FileMode, FileAccess, FileStat, IoResult, FilePermission}; use rt::rtio::{RtioFileStream, IoFactory, LocalIo}; use io; use option::{Some, None, Option}; +use owned::Box; use result::{Ok, Err}; use path; use path::{Path, GenericPath}; @@ -78,7 +79,7 @@ use vec::Vec; /// configured at creation time, via the `FileAccess` parameter to /// `File::open_mode()`. pub struct File { - fd: ~RtioFileStream:Send, + fd: Box<RtioFileStream:Send>, path: Path, last_nread: int, } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index ff276d02028..59a8c6f3439 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -227,6 +227,7 @@ use libc; use ops::{BitOr, BitAnd, Sub}; use os; use option::{Option, Some, None}; +use owned::Box; use path::Path; use result::{Ok, Err, Result}; use str::StrSlice; @@ -811,7 +812,7 @@ pub trait Reader { } } -impl Reader for ~Reader { +impl Reader for Box<Reader> { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.read(buf) } } @@ -1052,7 +1053,7 @@ pub trait Writer { } } -impl Writer for ~Writer { +impl Writer for Box<Writer> { fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write(buf) } fn flush(&mut self) -> IoResult<()> { self.flush() } } diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 0619c89aac1..69ccd2d28c9 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -23,6 +23,7 @@ use io::net::ip::SocketAddr; use io::{Reader, Writer, Listener, Acceptor}; use kinds::Send; use option::{None, Some, Option}; +use owned::Box; use rt::rtio::{IoFactory, LocalIo, RtioSocket, RtioTcpListener}; use rt::rtio::{RtioTcpAcceptor, RtioTcpStream}; @@ -45,11 +46,11 @@ use rt::rtio::{RtioTcpAcceptor, RtioTcpStream}; /// drop(stream); // close the connection /// ``` pub struct TcpStream { - obj: ~RtioTcpStream:Send + obj: Box<RtioTcpStream:Send>, } impl TcpStream { - fn new(s: ~RtioTcpStream:Send) -> TcpStream { + fn new(s: Box<RtioTcpStream:Send>) -> TcpStream { TcpStream { obj: s } } @@ -148,7 +149,7 @@ impl Writer for TcpStream { /// # } /// ``` pub struct TcpListener { - obj: ~RtioTcpListener:Send + obj: Box<RtioTcpListener:Send>, } impl TcpListener { @@ -181,7 +182,7 @@ impl Listener<TcpStream, TcpAcceptor> for TcpListener { /// a `TcpListener`'s `listen` method, and this object can be used to accept new /// `TcpStream` instances. pub struct TcpAcceptor { - obj: ~RtioTcpAcceptor:Send + obj: Box<RtioTcpAcceptor:Send>, } impl TcpAcceptor { diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 184069bab33..2cc0f853e35 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -19,6 +19,7 @@ use clone::Clone; use io::net::ip::SocketAddr; use io::{Reader, Writer, IoResult}; use kinds::Send; +use owned::Box; use result::{Ok, Err}; use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, LocalIo}; @@ -54,7 +55,7 @@ use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, LocalIo}; /// drop(socket); // close the socket /// ``` pub struct UdpSocket { - obj: ~RtioUdpSocket:Send + obj: Box<RtioUdpSocket:Send>, } impl UdpSocket { diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs index b75b797e974..f6e985dc278 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -31,6 +31,7 @@ use clone::Clone; use io::pipe::PipeStream; use io::{Listener, Acceptor, Reader, Writer, IoResult}; use kinds::Send; +use owned::Box; use rt::rtio::{IoFactory, LocalIo, RtioUnixListener}; use rt::rtio::{RtioUnixAcceptor, RtioPipe}; @@ -40,7 +41,7 @@ pub struct UnixStream { } impl UnixStream { - fn new(obj: ~RtioPipe:Send) -> UnixStream { + fn new(obj: Box<RtioPipe:Send>) -> UnixStream { UnixStream { obj: PipeStream::new(obj) } } @@ -107,7 +108,7 @@ impl Writer for UnixStream { /// A value that can listen for incoming named pipe connection requests. pub struct UnixListener { /// The internal, opaque runtime Unix listener. - obj: ~RtioUnixListener:Send, + obj: Box<RtioUnixListener:Send>, } impl UnixListener { @@ -149,7 +150,7 @@ impl Listener<UnixStream, UnixAcceptor> for UnixListener { /// A value that can accept named pipe connections, returned from `listen()`. pub struct UnixAcceptor { /// The internal, opaque runtime Unix acceptor. - obj: ~RtioUnixAcceptor:Send, + obj: Box<RtioUnixAcceptor:Send>, } impl UnixAcceptor { diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index 77a97f4e259..fbb0d5bc8d8 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -18,12 +18,13 @@ use prelude::*; use io::IoResult; use libc; +use owned::Box; use rt::rtio::{RtioPipe, LocalIo}; /// A synchronous, in-memory pipe. pub struct PipeStream { /// The internal, opaque runtime pipe object. - obj: ~RtioPipe:Send, + obj: Box<RtioPipe:Send>, } impl PipeStream { @@ -54,7 +55,7 @@ impl PipeStream { } #[doc(hidden)] - pub fn new(inner: ~RtioPipe:Send) -> PipeStream { + pub fn new(inner: Box<RtioPipe:Send>) -> PipeStream { PipeStream { obj: inner } } } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index b89e3ec3c77..1471a049bf3 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -17,6 +17,7 @@ use io::IoResult; use io; use libc; use mem; +use owned::Box; use rt::rtio::{RtioProcess, IoFactory, LocalIo}; /// Signal a process to exit, without forcibly killing it. Corresponds to @@ -52,7 +53,7 @@ use rt::rtio::{RtioProcess, IoFactory, LocalIo}; /// assert!(child.wait().success()); /// ``` pub struct Process { - handle: ~RtioProcess:Send, + handle: Box<RtioProcess:Send>, /// Handle to the child's stdin, if the `stdin` field of this process's /// `ProcessConfig` was `CreatePipe`. By default, this handle is `Some`. diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs index e7dae59acb8..4d294e84070 100644 --- a/src/libstd/io/signal.rs +++ b/src/libstd/io/signal.rs @@ -26,6 +26,7 @@ use iter::Iterator; use kinds::Send; use mem::drop; use option::{Some, None}; +use owned::Box; use result::{Ok, Err}; use rt::rtio::{IoFactory, LocalIo, RtioSignal}; use slice::ImmutableVector; @@ -81,7 +82,7 @@ pub enum Signum { /// ``` pub struct Listener { /// A map from signums to handles to keep the handles in memory - handles: Vec<(Signum, ~RtioSignal:Send)>, + handles: Vec<(Signum, Box<RtioSignal:Send>)>, /// This is where all the handles send signums, which are received by /// the clients from the receiver. tx: Sender<Signum>, diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 7cb58e1ea48..613e9f027a4 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -34,6 +34,7 @@ use libc; use kinds::Send; use mem::replace; use option::{Option, Some, None}; +use owned::Box; use prelude::drop; use result::{Ok, Err}; use rt; @@ -71,8 +72,8 @@ use str::StrSlice; // tl;dr; TTY works on everything but when windows stdout is redirected, in that // case pipe also doesn't work, but magically file does! enum StdSource { - TTY(~RtioTTY:Send), - File(~RtioFileStream:Send), + TTY(Box<RtioTTY:Send>), + File(Box<RtioFileStream:Send>), } fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T { @@ -153,10 +154,9 @@ pub fn stderr_raw() -> StdWriter { src(libc::STDERR_FILENO, false, |src| StdWriter { inner: src }) } -fn reset_helper(w: ~Writer:Send, - f: |&mut Task, ~Writer:Send| -> Option<~Writer:Send>) - -> Option<~Writer:Send> -{ +fn reset_helper(w: Box<Writer:Send>, + f: |&mut Task, Box<Writer:Send>| -> Option<Box<Writer:Send>>) + -> Option<Box<Writer:Send>> { let mut t = Local::borrow(None::<Task>); // Be sure to flush any pending output from the writer match f(&mut *t, w) { @@ -178,7 +178,7 @@ fn reset_helper(w: ~Writer:Send, /// /// Note that this does not need to be called for all new tasks; the default /// output handle is to the process's stdout stream. -pub fn set_stdout(stdout: ~Writer:Send) -> Option<~Writer:Send> { +pub fn set_stdout(stdout: Box<Writer:Send>) -> Option<Box<Writer:Send>> { reset_helper(stdout, |t, w| replace(&mut t.stdout, Some(w))) } @@ -190,7 +190,7 @@ pub fn set_stdout(stdout: ~Writer:Send) -> Option<~Writer:Send> { /// /// Note that this does not need to be called for all new tasks; the default /// output handle is to the process's stderr stream. -pub fn set_stderr(stderr: ~Writer:Send) -> Option<~Writer:Send> { +pub fn set_stderr(stderr: Box<Writer:Send>) -> Option<Box<Writer:Send>> { reset_helper(stderr, |t, w| replace(&mut t.stderr, Some(w))) } @@ -205,7 +205,7 @@ pub fn set_stderr(stderr: ~Writer:Send) -> Option<~Writer:Send> { // }) // }) fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) { - let task: Option<~Task> = Local::try_take(); + let task: Option<Box<Task>> = Local::try_take(); let result = match task { Some(mut task) => { // Printing may run arbitrary code, so ensure that the task is in @@ -216,7 +216,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) { Local::put(task); if my_stdout.is_none() { - my_stdout = Some(box stdout() as ~Writer:Send); + my_stdout = Some(box stdout() as Box<Writer:Send>); } let ret = f(*my_stdout.get_mut_ref()); diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index 1ca36df968c..96c4083e7ed 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -20,6 +20,7 @@ and create receivers which will receive notifications after a period of time. use comm::Receiver; use io::IoResult; use kinds::Send; +use owned::Box; use rt::rtio::{IoFactory, LocalIo, RtioTimer}; /// A synchronous timer object @@ -63,7 +64,7 @@ use rt::rtio::{IoFactory, LocalIo, RtioTimer}; /// # } /// ``` pub struct Timer { - obj: ~RtioTimer:Send, + obj: Box<RtioTimer:Send>, } /// Sleep the current task for `msecs` milliseconds. diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 5cae79d371f..b2e6b27caab 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -13,6 +13,7 @@ use prelude::*; use cmp; use io; +use owned::Box; use slice::bytes::MutableByteVector; /// Wraps a `Reader`, limiting the number of bytes that can be read from it. @@ -85,12 +86,12 @@ impl Reader for NullReader { /// A `Writer` which multiplexes writes to a set of `Writers`. pub struct MultiWriter { - writers: Vec<~Writer> + writers: Vec<Box<Writer>> } impl MultiWriter { /// Creates a new `MultiWriter` - pub fn new(writers: Vec<~Writer>) -> MultiWriter { + pub fn new(writers: Vec<Box<Writer>>) -> MultiWriter { MultiWriter { writers: writers } } } @@ -199,6 +200,7 @@ pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> io::IoResult<()> { mod test { use io; use io::{MemReader, MemWriter}; + use owned::Box; use super::*; use prelude::*; @@ -273,8 +275,8 @@ mod test { } } - let mut multi = MultiWriter::new(vec!(box TestWriter as ~Writer, - box TestWriter as ~Writer)); + let mut multi = MultiWriter::new(vec!(box TestWriter as Box<Writer>, + box TestWriter as Box<Writer>)); multi.write([1, 2, 3]).unwrap(); assert_eq!(2, unsafe { writes }); assert_eq!(0, unsafe { flushes }); diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index daeba2365e6..291507c1aaf 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -2333,6 +2333,7 @@ mod tests { use prelude::*; use cmp; + use owned::Box; use uint; use num; @@ -2634,7 +2635,7 @@ mod tests { #[test] fn test_all() { - let v: ~&[int] = box &[1, 2, 3, 4, 5]; + let v: Box<&[int]> = box &[1, 2, 3, 4, 5]; assert!(v.iter().all(|&x| x < 10)); assert!(!v.iter().all(|&x| x % 2 == 0)); assert!(!v.iter().all(|&x| x > 100)); @@ -2643,7 +2644,7 @@ mod tests { #[test] fn test_any() { - let v: ~&[int] = box &[1, 2, 3, 4, 5]; + let v: Box<&[int]> = box &[1, 2, 3, 4, 5]; assert!(v.iter().any(|&x| x < 10)); assert!(v.iter().any(|&x| x % 2 == 0)); assert!(!v.iter().any(|&x| x > 100)); diff --git a/src/libstd/kinds.rs b/src/libstd/kinds.rs index f9827d7fa59..6ef71d3360a 100644 --- a/src/libstd/kinds.rs +++ b/src/libstd/kinds.rs @@ -48,7 +48,7 @@ pub trait Copy { /// `Share`, and so are simple aggregate types containing them (like /// tuples, structs and enums). More instances of basic `Share` types /// include "immutable" types like `&T` and those with simple -/// inherited mutability, such as `~T`, `Vec<T>` and most other +/// inherited mutability, such as `Box<T>`, `Vec<T>` and most other /// collection types. (Generic parameters need to be `Share` for their /// container to be `Share`.) /// diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index c34ebfdf7c2..bf24bf405a0 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -131,6 +131,7 @@ extern crate libc; #[cfg(test)] pub use ops = realstd::ops; #[cfg(test)] pub use cmp = realstd::cmp; #[cfg(test)] pub use ty = realstd::ty; +#[cfg(test)] pub use owned = realstd::owned; // Run tests with libgreen instead of libnative. // @@ -188,7 +189,6 @@ pub mod strbuf; pub mod ascii; pub mod ptr; -pub mod owned; mod managed; mod reference; pub mod rc; @@ -201,6 +201,7 @@ pub mod gc; #[cfg(not(test))] pub mod ops; #[cfg(not(test))] pub mod cmp; #[cfg(not(test))] pub mod ty; +#[cfg(not(test))] pub mod owned; /* Common traits */ diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index e5c7ba4aa54..8855dabe353 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -45,6 +45,7 @@ use iter::{Iterator}; use kinds::Send; use mem::replace; use option::{None, Option, Some}; +use owned::Box; use rt::task::{Task, LocalStorage}; use slice::{ImmutableVector, MutableVector}; use vec::Vec; @@ -91,7 +92,7 @@ impl<T: 'static> LocalData for T {} // a proper map. #[doc(hidden)] pub type Map = Vec<Option<(*u8, TLSValue, LoanState)>>; -type TLSValue = ~LocalData:Send; +type TLSValue = Box<LocalData:Send>; // Gets the map from the runtime. Lazily initialises if not done so already. unsafe fn get_local_map() -> &mut Map { @@ -161,7 +162,7 @@ pub fn pop<T: 'static>(key: Key<T>) -> Option<T> { // Move `data` into transmute to get out the memory that it // owns, we must free it manually later. - let (_vtable, alloc): (uint, ~T) = unsafe { + let (_vtable, alloc): (uint, Box<T>) = unsafe { cast::transmute(data) }; @@ -252,11 +253,12 @@ fn get_with<T:'static, want.describe(), cur.describe()); } } - // data was created with `~T as ~LocalData`, so we extract - // pointer part of the trait, (as ~T), and then use - // compiler coercions to achieve a '&' pointer. + // data was created with `box T as Box<LocalData>`, so we + // extract pointer part of the trait, (as Box<T>), and + // then use compiler coercions to achieve a '&' pointer. unsafe { - match *cast::transmute::<&TLSValue, &(uint, ~T)>(data){ + match *cast::transmute::<&TLSValue, + &(uint, Box<T>)>(data){ (_vtable, ref alloc) => { let value: &T = *alloc; ret = f(Some(value)); @@ -297,12 +299,12 @@ pub fn set<T: 'static>(key: Key<T>, data: T) { let keyval = key_to_key_value(key); // When the task-local map is destroyed, all the data needs to be cleaned - // up. For this reason we can't do some clever tricks to store '~T' as a - // '*c_void' or something like that. To solve the problem, we cast + // up. For this reason we can't do some clever tricks to store 'Box<T>' as + // a '*c_void' or something like that. To solve the problem, we cast // everything to a trait (LocalData) which is then stored inside the map. // Upon destruction of the map, all the objects will be destroyed and the // traits have enough information about them to destroy themselves. - let data = box data as ~LocalData:; + let data = box data as Box<LocalData:>; fn insertion_position(map: &mut Map, key: *u8) -> Option<uint> { @@ -330,7 +332,7 @@ pub fn set<T: 'static>(key: Key<T>, data: T) { // transmute here to add the Send bound back on. This doesn't actually // matter because TLS will always own the data (until its moved out) and // we're not actually sending it to other schedulers or anything. - let data: ~LocalData:Send = unsafe { cast::transmute(data) }; + let data: Box<LocalData:Send> = unsafe { cast::transmute(data) }; match insertion_position(map, keyval) { Some(i) => { *map.get_mut(i) = Some((keyval, data, NoLoan)); } None => { map.push(Some((keyval, data, NoLoan))); } @@ -353,6 +355,7 @@ pub fn modify<T: 'static>(key: Key<T>, f: |Option<T>| -> Option<T>) { mod tests { use prelude::*; use super::*; + use owned::Box; use task; use str::StrSlice; @@ -485,7 +488,7 @@ mod tests { #[test] fn test_owned() { - static key: Key<~int> = &Key; + static key: Key<Box<int>> = &Key; set(key, box 1); get(key, |v| { diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index b04ca63e55e..4ae3d453f03 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -19,9 +19,9 @@ /// The entry point for failure of rust tasks. /// /// This macro is used to inject failure into a rust task, causing the task to -/// unwind and fail entirely. Each task's failure can be reaped as the `~Any` -/// type, and the single-argument form of the `fail!` macro will be the value -/// which is transmitted. +/// unwind and fail entirely. Each task's failure can be reaped as the +/// `Box<Any>` type, and the single-argument form of the `fail!` macro will be +/// the value which is transmitted. /// /// The multi-argument form of this macro fails with a string and has the /// `format!` syntax for building a string. diff --git a/src/libstd/option.rs b/src/libstd/option.rs index eabaf4f2f9a..fa7b5c94857 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -54,7 +54,7 @@ //! //! Rust's pointer types must always point to a valid location; there are //! no "null" pointers. Instead, Rust has *optional* pointers, like -//! the optional owned box, `Option<~T>`. +//! the optional owned box, `Option<Box<T>>`. //! //! The following example uses `Option` to create an optional box of //! `int`. Notice that in order to use the inner `int` value first the @@ -63,13 +63,13 @@ //! not (`None`). //! //! ``` -//! let optional: Option<~int> = None; +//! let optional: Option<Box<int>> = None; //! check_optional(&optional); //! -//! let optional: Option<~int> = Some(~9000); +//! let optional: Option<Box<int>> = Some(box 9000); //! check_optional(&optional); //! -//! fn check_optional(optional: &Option<~int>) { +//! fn check_optional(optional: &Option<Box<int>>) { //! match *optional { //! Some(ref p) => println!("have value {}", p), //! None => println!("have no value") @@ -79,7 +79,7 @@ //! //! This usage of `Option` to create safe nullable pointers is so //! common that Rust does special optimizations to make the -//! representation of `Option<~T>` a single pointer. Optional pointers +//! representation of `Option<Box<T>>` a single pointer. Optional pointers //! in Rust are stored as efficiently as any other pointer type. //! //! # Examples diff --git a/src/libstd/owned.rs b/src/libstd/owned.rs index 826ada8f252..48b80e0ca8e 100644 --- a/src/libstd/owned.rs +++ b/src/libstd/owned.rs @@ -35,30 +35,30 @@ pub struct Box<T>(*T); pub struct Box<T>(*T); #[cfg(not(test))] -impl<T:Eq> Eq for ~T { +impl<T:Eq> Eq for Box<T> { #[inline] - fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) } + fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) } #[inline] - fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) } + fn ne(&self, other: &Box<T>) -> bool { *(*self) != *(*other) } } #[cfg(not(test))] -impl<T:Ord> Ord for ~T { +impl<T:Ord> Ord for Box<T> { #[inline] - fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) } + fn lt(&self, other: &Box<T>) -> bool { *(*self) < *(*other) } #[inline] - fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) } + fn le(&self, other: &Box<T>) -> bool { *(*self) <= *(*other) } #[inline] - fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) } + fn ge(&self, other: &Box<T>) -> bool { *(*self) >= *(*other) } #[inline] - fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) } + fn gt(&self, other: &Box<T>) -> bool { *(*self) > *(*other) } } #[cfg(not(test))] -impl<T: TotalOrd> TotalOrd for ~T { +impl<T: TotalOrd> TotalOrd for Box<T> { #[inline] - fn cmp(&self, other: &~T) -> Ordering { (**self).cmp(*other) } + fn cmp(&self, other: &Box<T>) -> Ordering { (**self).cmp(*other) } } #[cfg(not(test))] -impl<T: TotalEq> TotalEq for ~T {} +impl<T: TotalEq> TotalEq for Box<T> {} diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 32df3869534..ee1d5d4a35b 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -65,6 +65,7 @@ pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize}; pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul}; pub use num::{Signed, Unsigned}; pub use num::{Primitive, Int, Float, ToPrimitive, FromPrimitive}; +pub use owned::Box; pub use path::{GenericPath, Path, PosixPath, WindowsPath}; pub use ptr::RawPtr; pub use io::{Buffer, Writer, Reader, Seek}; diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index b4b5185c221..dac727c2aa4 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -41,11 +41,11 @@ //! and requires no resource management later, //! but you must not use the pointer after its lifetime. //! -//! ## 2. Transmute an owned box (`~T`). +//! ## 2. Transmute an owned box (`Box<T>`). //! //! The `transmute` function takes, by value, whatever it's given //! and returns it as whatever type is requested, as long as the -//! types are the same size. Because `~T` and `*T` have the same +//! types are the same size. Because `Box<T>` and `*T` have the same //! representation they can be trivially, //! though unsafely, transformed from one type to the other. //! @@ -53,15 +53,15 @@ //! use std::cast; //! //! unsafe { -//! let my_num: ~int = ~10; +//! let my_num: Box<int> = box 10; //! let my_num: *int = cast::transmute(my_num); -//! let my_speed: ~int = ~88; +//! let my_speed: Box<int> = box 88; //! let my_speed: *mut int = cast::transmute(my_speed); //! -//! // By taking ownership of the original `~T` though +//! // By taking ownership of the original `Box<T>` though //! // we are obligated to transmute it back later to be destroyed. -//! drop(cast::transmute::<_, ~int>(my_speed)); -//! drop(cast::transmute::<_, ~int>(my_num)); +//! drop(cast::transmute::<_, Box<int>>(my_speed)); +//! drop(cast::transmute::<_, Box<int>>(my_num)); //! } //! ``` //! diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index ddfc5b58532..ec7b6cfa355 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -18,6 +18,7 @@ Runtime type reflection use intrinsics::{Disr, Opaque, TyDesc, TyVisitor}; use mem; +use owned::Box; /** * Trait for visitor that wishes to reflect on data. To use this, create a @@ -225,9 +226,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { } fn visit_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - self.align_to::<~u8>(); + self.align_to::<Box<u8>>(); if ! self.inner.visit_uniq(mtbl, inner) { return false; } - self.bump_past::<~u8>(); + self.bump_past::<Box<u8>>(); true } @@ -417,9 +418,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> { } fn visit_trait(&mut self, name: &str) -> bool { - self.align_to::<~TyVisitor>(); + self.align_to::<Box<TyVisitor>>(); if ! self.inner.visit_trait(name) { return false; } - self.bump_past::<~TyVisitor>(); + self.bump_past::<Box<TyVisitor>>(); true } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index cdcd7c23215..79b927c8d77 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -320,7 +320,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { } fn visit_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool { - try!(self, self.writer.write(['~' as u8])); + try!(self, self.writer.write("box ".as_bytes())); self.get::<*u8>(|this, b| { this.visit_ptr_inner(*b, inner) }) @@ -353,7 +353,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { self.get::<&raw::Vec<()>>(|this, b| { - try!(this, this.writer.write(['~' as u8])); + try!(this, this.writer.write("box ".as_bytes())); this.write_unboxed_vec_repr(mtbl, *b, inner) }) } @@ -624,6 +624,7 @@ fn test_repr() { use io::stdio::println; use char::is_alphabetic; use mem::swap; + use owned::Box; fn exact_test<T>(t: &T, e:&str) { let mut m = io::MemWriter::new(); @@ -641,7 +642,7 @@ fn test_repr() { exact_test(&("he\u10f3llo".to_owned()), "~\"he\\u10f3llo\""); exact_test(&(@10), "@10"); - exact_test(&(box 10), "~10"); + exact_test(&(box 10), "box 10"); exact_test(&(&10), "&10"); let mut x = 10; exact_test(&(&mut x), "&mut 10"); @@ -650,8 +651,6 @@ fn test_repr() { exact_test(&(0 as *mut ()), "(0x0 as *mut ())"); exact_test(&(1,), "(1,)"); - exact_test(&(box ["hi", "there"]), - "~[\"hi\", \"there\"]"); exact_test(&(&["hi", "there"]), "&[\"hi\", \"there\"]"); exact_test(&(P{a:10, b:1.234}), @@ -659,7 +658,7 @@ fn test_repr() { exact_test(&(@P{a:10, b:1.234}), "@repr::P{a: 10, b: 1.234f64}"); exact_test(&(box P{a:10, b:1.234}), - "~repr::P{a: 10, b: 1.234f64}"); + "box repr::P{a: 10, b: 1.234f64}"); exact_test(&(10u8, "hello".to_owned()), "(10u8, ~\"hello\")"); exact_test(&(10u16, "hello".to_owned()), @@ -680,10 +679,6 @@ fn test_repr() { exact_test(&println, "fn(&str)"); exact_test(&swap::<int>, "fn(&mut int, &mut int)"); exact_test(&is_alphabetic, "fn(char) -> bool"); - exact_test(&(box 5 as ~ToStr), "~to_str::ToStr<no-bounds>"); - - struct Foo; - exact_test(&(box [Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]"); struct Bar(int, int); exact_test(&(Bar(2, 2)), "repr::test_repr::Bar(2, 2)"); diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 092efcad831..17e6f6b7698 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -67,6 +67,7 @@ mod imp { use clone::Clone; use option::{Option, Some, None}; use iter::Iterator; + use owned::Box; use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; use mem; #[cfg(not(test))] use str::StrSlice; @@ -91,7 +92,7 @@ mod imp { with_lock(|| unsafe { let ptr = get_global_ptr(); let val = mem::replace(&mut *ptr, None); - val.as_ref().map(|s: &~~[~[u8]]| (**s).clone()) + val.as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone()) }) } @@ -106,7 +107,7 @@ mod imp { pub fn clone() -> Option<~[~[u8]]> { with_lock(|| unsafe { let ptr = get_global_ptr(); - (*ptr).as_ref().map(|s: &~~[~[u8]]| (**s).clone()) + (*ptr).as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone()) }) } @@ -117,7 +118,7 @@ mod imp { } } - fn get_global_ptr() -> *mut Option<~~[~[u8]]> { + fn get_global_ptr() -> *mut Option<Box<~[~[u8]]>> { unsafe { cast::transmute(&global_args_ptr) } } diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 2c8e159aeb9..051bc494adc 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -17,6 +17,7 @@ use iter::Iterator; use kinds::Send; use mem; use option::{Some, None}; +use owned::Box; use ptr::RawPtr; use unstable::sync::Exclusive; use slice::OwnedVector; @@ -36,7 +37,7 @@ pub fn init() { unsafe { rtassert!(!RUNNING); rtassert!(QUEUE.is_null()); - let state: ~Queue = box Exclusive::new(vec!()); + let state: Box<Queue> = box Exclusive::new(vec!()); QUEUE = cast::transmute(state); } } @@ -58,7 +59,7 @@ pub fn run() { rtassert!(!RUNNING); rtassert!(!QUEUE.is_null()); RUNNING = true; - let state: ~Queue = cast::transmute(QUEUE); + let state: Box<Queue> = cast::transmute(QUEUE); QUEUE = 0 as *mut Queue; let mut vec = None; state.with(|arr| { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 26494f1acd9..ee8041f6880 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -129,7 +129,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { // see src/librustc/back/link.rs for these mappings demangle! ( "$SP$" => "@", - "$UP$" => "~", + "$UP$" => "Box", "$RP$" => "*", "$BP$" => "&", "$LT$" => "<", @@ -858,15 +858,15 @@ mod test { #[test] fn demangle_dollars() { - t!("_ZN4$UP$E", "~"); - t!("_ZN8$UP$testE", "~test"); - t!("_ZN8$UP$test4foobE", "~test::foob"); + t!("_ZN4$UP$E", "Box"); + t!("_ZN8$UP$testE", "Boxtest"); + t!("_ZN8$UP$test4foobE", "Boxtest::foob"); t!("_ZN8$x20test4foobE", " test::foob"); } #[test] fn demangle_many_dollars() { t!("_ZN12test$x20test4foobE", "test test::foob"); - t!("_ZN12test$UP$test4foobE", "test~test::foob"); + t!("_ZN12test$UP$test4foobE", "testBoxtest::foob"); } } diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 094bbd13889..7d54c3faf42 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -72,9 +72,10 @@ pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 { #[lang="exchange_malloc"] #[inline] pub unsafe fn exchange_malloc(size: uint) -> *mut u8 { - // The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size - // allocations can point to this `static`. It would be incorrect to use a null - // pointer, due to enums assuming types like unique pointers are never null. + // The compiler never calls `exchange_free` on Box<ZeroSizeType>, so + // zero-size allocations can point to this `static`. It would be incorrect + // to use a null pointer, due to enums assuming types like unique pointers + // are never null. static EMPTY: () = (); if size == 0 { diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index 828bbc118c1..05d1f1764b5 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -9,17 +9,18 @@ // except according to those terms. use option::Option; +use owned::Box; use rt::task::Task; use rt::local_ptr; /// Encapsulates some task-local data. pub trait Local<Borrowed> { - fn put(value: ~Self); - fn take() -> ~Self; - fn try_take() -> Option<~Self>; + fn put(value: Box<Self>); + fn take() -> Box<Self>; + fn try_take() -> Option<Box<Self>>; fn exists(unused_value: Option<Self>) -> bool; fn borrow(unused_value: Option<Self>) -> Borrowed; - unsafe fn unsafe_take() -> ~Self; + unsafe fn unsafe_take() -> Box<Self>; unsafe fn unsafe_borrow() -> *mut Self; unsafe fn try_unsafe_borrow() -> Option<*mut Self>; } @@ -27,11 +28,11 @@ pub trait Local<Borrowed> { #[allow(visible_private_types)] impl Local<local_ptr::Borrowed<Task>> for Task { #[inline] - fn put(value: ~Task) { unsafe { local_ptr::put(value) } } + fn put(value: Box<Task>) { unsafe { local_ptr::put(value) } } #[inline] - fn take() -> ~Task { unsafe { local_ptr::take() } } + fn take() -> Box<Task> { unsafe { local_ptr::take() } } #[inline] - fn try_take() -> Option<~Task> { unsafe { local_ptr::try_take() } } + fn try_take() -> Option<Box<Task>> { unsafe { local_ptr::try_take() } } fn exists(_: Option<Task>) -> bool { local_ptr::exists() } #[inline] fn borrow(_: Option<Task>) -> local_ptr::Borrowed<Task> { @@ -40,7 +41,7 @@ impl Local<local_ptr::Borrowed<Task>> for Task { } } #[inline] - unsafe fn unsafe_take() -> ~Task { local_ptr::unsafe_take() } + unsafe fn unsafe_take() -> Box<Task> { local_ptr::unsafe_take() } #[inline] unsafe fn unsafe_borrow() -> *mut Task { local_ptr::unsafe_borrow() } #[inline] @@ -54,6 +55,7 @@ mod test { use option::{None, Option}; use unstable::run_in_bare_thread; use super::*; + use owned::Box; use rt::task::Task; #[test] @@ -61,7 +63,7 @@ mod test { run_in_bare_thread(proc() { let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -71,11 +73,11 @@ mod test { run_in_bare_thread(proc() { let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -89,7 +91,7 @@ mod test { unsafe { let _task: *mut Task = Local::unsafe_borrow(); } - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -104,7 +106,7 @@ mod test { let _ = Local::borrow(None::<Task>); } - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -115,15 +117,15 @@ mod test { let task = box Task::new(); Local::put(task); - let t: ~Task = Local::try_take().unwrap(); - let u: Option<~Task> = Local::try_take(); + let t: Box<Task> = Local::try_take().unwrap(); + let u: Option<Box<Task>> = Local::try_take(); assert!(u.is_none()); cleanup_task(t); }); } - fn cleanup_task(mut t: ~Task) { + fn cleanup_task(mut t: Box<Task>) { t.destroyed = true; } diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index f60cfa23e81..39c0d9a5482 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -10,7 +10,7 @@ //! Access to a single thread-local pointer. //! -//! The runtime will use this for storing ~Task. +//! The runtime will use this for storing Box<Task>. //! //! FIXME: Add runtime checks for usage of inconsistent pointer types. //! and for overwriting an existing pointer. @@ -19,6 +19,7 @@ use cast; use ops::{Drop, Deref, DerefMut}; +use owned::Box; use ptr::RawPtr; #[cfg(windows)] // mingw-w32 doesn't like thread_local things @@ -43,7 +44,7 @@ impl<T> Drop for Borrowed<T> { if self.val.is_null() { rtabort!("Aiee, returning null borrowed object!"); } - let val: ~T = cast::transmute(self.val); + let val: Box<T> = cast::transmute(self.val); put::<T>(val); rtassert!(exists()); } @@ -84,6 +85,7 @@ pub unsafe fn borrow<T>() -> Borrowed<T> { pub mod compiled { use cast; use option::{Option, Some, None}; + use owned::Box; use ptr::RawPtr; #[cfg(test)] @@ -154,7 +156,7 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn put<T>(sched: ~T) { + pub unsafe fn put<T>(sched: Box<T>) { RT_TLS_PTR = cast::transmute(sched) } @@ -164,10 +166,10 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn take<T>() -> ~T { + pub unsafe fn take<T>() -> Box<T> { let ptr = RT_TLS_PTR; rtassert!(!ptr.is_null()); - let ptr: ~T = cast::transmute(ptr); + let ptr: Box<T> = cast::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` RT_TLS_PTR = cast::transmute(0); ptr @@ -179,12 +181,12 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn try_take<T>() -> Option<~T> { + pub unsafe fn try_take<T>() -> Option<Box<T>> { let ptr = RT_TLS_PTR; if ptr.is_null() { None } else { - let ptr: ~T = cast::transmute(ptr); + let ptr: Box<T> = cast::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` RT_TLS_PTR = cast::transmute(0); Some(ptr) @@ -198,7 +200,7 @@ pub mod compiled { /// Does not validate the pointer type. /// Leaves the old pointer in TLS for speed. #[inline(never)] // see comments above - pub unsafe fn unsafe_take<T>() -> ~T { + pub unsafe fn unsafe_take<T>() -> Box<T> { cast::transmute(RT_TLS_PTR) } @@ -234,6 +236,7 @@ pub mod compiled { pub mod native { use cast; use option::{Option, Some, None}; + use owned::Box; use ptr; use ptr::RawPtr; use tls = rt::thread_local_storage; @@ -259,7 +262,7 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn put<T>(sched: ~T) { + pub unsafe fn put<T>(sched: Box<T>) { let key = tls_key(); let void_ptr: *mut u8 = cast::transmute(sched); tls::set(key, void_ptr); @@ -271,13 +274,13 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn take<T>() -> ~T { + pub unsafe fn take<T>() -> Box<T> { let key = tls_key(); let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box<T> = cast::transmute(void_ptr); tls::set(key, ptr::mut_null()); return ptr; } @@ -288,14 +291,14 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn try_take<T>() -> Option<~T> { + pub unsafe fn try_take<T>() -> Option<Box<T>> { match maybe_tls_key() { Some(key) => { let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { None } else { - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box<T> = cast::transmute(void_ptr); tls::set(key, ptr::mut_null()); Some(ptr) } @@ -311,13 +314,13 @@ pub mod native { /// Does not validate the pointer type. /// Leaves the old pointer in TLS for speed. #[inline] - pub unsafe fn unsafe_take<T>() -> ~T { + pub unsafe fn unsafe_take<T>() -> Box<T> { let key = tls_key(); let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box<T> = cast::transmute(void_ptr); return ptr; } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index b407bf8897c..e79e3056838 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -57,6 +57,7 @@ Several modules in `core` are clients of `rt`: use any::Any; use kinds::Send; use option::Option; +use owned::Box; use result::Result; use task::TaskOpts; @@ -151,22 +152,25 @@ pub static DEFAULT_ERROR_CODE: int = 101; pub trait Runtime { // Necessary scheduling functions, used for channels and blocking I/O // (sometimes). - fn yield_now(~self, cur_task: ~Task); - fn maybe_yield(~self, cur_task: ~Task); - fn deschedule(~self, times: uint, cur_task: ~Task, + fn yield_now(~self, cur_task: Box<Task>); + fn maybe_yield(~self, cur_task: Box<Task>); + fn deschedule(~self, times: uint, cur_task: Box<Task>, f: |BlockedTask| -> Result<(), BlockedTask>); - fn reawaken(~self, to_wake: ~Task); + fn reawaken(~self, to_wake: Box<Task>); // Miscellaneous calls which are very different depending on what context // you're in. - fn spawn_sibling(~self, cur_task: ~Task, opts: TaskOpts, f: proc():Send); + fn spawn_sibling(~self, + cur_task: Box<Task>, + opts: TaskOpts, + f: proc():Send); fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>>; /// The (low, high) edges of the current stack. fn stack_bounds(&self) -> (uint, uint); // (lo, hi) fn can_block(&self) -> bool; // FIXME: This is a serious code smell and this should not exist at all. - fn wrap(~self) -> ~Any; + fn wrap(~self) -> Box<Any>; } /// One-time runtime initialization. diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index fc8c79549af..fe9f4932a2a 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -18,6 +18,7 @@ use libc; use kinds::Send; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use path::Path; use result::Err; use rt::local::Local; @@ -40,9 +41,10 @@ pub trait Callback { pub trait EventLoop { fn run(&mut self); fn callback(&mut self, arg: proc():Send); - fn pausable_idle_callback(&mut self, - ~Callback:Send) -> ~PausableIdleCallback:Send; - fn remote_callback(&mut self, ~Callback:Send) -> ~RemoteCallback:Send; + fn pausable_idle_callback(&mut self, Box<Callback:Send>) + -> Box<PausableIdleCallback:Send>; + fn remote_callback(&mut self, Box<Callback:Send>) + -> Box<RemoteCallback:Send>; /// The asynchronous I/O services. Not all event loops may provide one. fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>; @@ -114,7 +116,7 @@ impl<'a> LocalIo<'a> { // // In order to get around this, we just transmute a copy out of the task // in order to have what is likely a static lifetime (bad). - let mut t: ~Task = Local::take(); + let mut t: Box<Task> = Local::take(); let ret = t.local_io().map(|t| { unsafe { cast::transmute_copy(&t) } }); @@ -149,21 +151,23 @@ impl<'a> LocalIo<'a> { pub trait IoFactory { // networking fn tcp_connect(&mut self, addr: SocketAddr, - timeout: Option<u64>) -> IoResult<~RtioTcpStream:Send>; - fn tcp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioTcpListener:Send>; - fn udp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioUdpSocket:Send>; + timeout: Option<u64>) -> IoResult<Box<RtioTcpStream:Send>>; + fn tcp_bind(&mut self, addr: SocketAddr) + -> IoResult<Box<RtioTcpListener:Send>>; + fn udp_bind(&mut self, addr: SocketAddr) + -> IoResult<Box<RtioUdpSocket:Send>>; fn unix_bind(&mut self, path: &CString) - -> IoResult<~RtioUnixListener:Send>; + -> IoResult<Box<RtioUnixListener:Send>>; fn unix_connect(&mut self, path: &CString, - timeout: Option<u64>) -> IoResult<~RtioPipe:Send>; + timeout: Option<u64>) -> IoResult<Box<RtioPipe:Send>>; fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>, hint: Option<ai::Hint>) -> IoResult<~[ai::Info]>; // filesystem operations fn fs_from_raw_fd(&mut self, fd: c_int, close: CloseBehavior) - -> ~RtioFileStream:Send; + -> Box<RtioFileStream:Send>; fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess) - -> IoResult<~RtioFileStream:Send>; + -> IoResult<Box<RtioFileStream:Send>>; fn fs_unlink(&mut self, path: &CString) -> IoResult<()>; fn fs_stat(&mut self, path: &CString) -> IoResult<FileStat>; fn fs_mkdir(&mut self, path: &CString, @@ -184,23 +188,24 @@ pub trait IoFactory { IoResult<()>; // misc - fn timer_init(&mut self) -> IoResult<~RtioTimer:Send>; + fn timer_init(&mut self) -> IoResult<Box<RtioTimer:Send>>; fn spawn(&mut self, config: ProcessConfig) - -> IoResult<(~RtioProcess:Send, ~[Option<~RtioPipe:Send>])>; + -> IoResult<(Box<RtioProcess:Send>, + ~[Option<Box<RtioPipe:Send>>])>; fn kill(&mut self, pid: libc::pid_t, signal: int) -> IoResult<()>; - fn pipe_open(&mut self, fd: c_int) -> IoResult<~RtioPipe:Send>; + fn pipe_open(&mut self, fd: c_int) -> IoResult<Box<RtioPipe:Send>>; fn tty_open(&mut self, fd: c_int, readable: bool) - -> IoResult<~RtioTTY:Send>; + -> IoResult<Box<RtioTTY:Send>>; fn signal(&mut self, signal: Signum, channel: Sender<Signum>) - -> IoResult<~RtioSignal:Send>; + -> IoResult<Box<RtioSignal:Send>>; } pub trait RtioTcpListener : RtioSocket { - fn listen(~self) -> IoResult<~RtioTcpAcceptor:Send>; + fn listen(~self) -> IoResult<Box<RtioTcpAcceptor:Send>>; } pub trait RtioTcpAcceptor : RtioSocket { - fn accept(&mut self) -> IoResult<~RtioTcpStream:Send>; + fn accept(&mut self) -> IoResult<Box<RtioTcpStream:Send>>; fn accept_simultaneously(&mut self) -> IoResult<()>; fn dont_accept_simultaneously(&mut self) -> IoResult<()>; fn set_timeout(&mut self, timeout: Option<u64>); @@ -214,7 +219,7 @@ pub trait RtioTcpStream : RtioSocket { fn nodelay(&mut self) -> IoResult<()>; fn keepalive(&mut self, delay_in_seconds: uint) -> IoResult<()>; fn letdie(&mut self) -> IoResult<()>; - fn clone(&self) -> ~RtioTcpStream:Send; + fn clone(&self) -> Box<RtioTcpStream:Send>; fn close_write(&mut self) -> IoResult<()>; } @@ -238,7 +243,7 @@ pub trait RtioUdpSocket : RtioSocket { fn hear_broadcasts(&mut self) -> IoResult<()>; fn ignore_broadcasts(&mut self) -> IoResult<()>; - fn clone(&self) -> ~RtioUdpSocket:Send; + fn clone(&self) -> Box<RtioUdpSocket:Send>; } pub trait RtioTimer { @@ -268,15 +273,15 @@ pub trait RtioProcess { pub trait RtioPipe { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint>; fn write(&mut self, buf: &[u8]) -> IoResult<()>; - fn clone(&self) -> ~RtioPipe:Send; + fn clone(&self) -> Box<RtioPipe:Send>; } pub trait RtioUnixListener { - fn listen(~self) -> IoResult<~RtioUnixAcceptor:Send>; + fn listen(~self) -> IoResult<Box<RtioUnixAcceptor:Send>>; } pub trait RtioUnixAcceptor { - fn accept(&mut self) -> IoResult<~RtioPipe:Send>; + fn accept(&mut self) -> IoResult<Box<RtioPipe:Send>>; fn set_timeout(&mut self, timeout: Option<u64>); } diff --git a/src/libstd/rt/stack.rs b/src/libstd/rt/stack.rs index 963ff000c4a..b9bcd1de8fc 100644 --- a/src/libstd/rt/stack.rs +++ b/src/libstd/rt/stack.rs @@ -37,6 +37,7 @@ pub static RED_ZONE: uint = 20 * 1024; #[cfg(not(test))] // in testing, use the original libstd's version pub extern "C" fn rust_stack_exhausted() { use option::{Option, None, Some}; + use owned::Box; use rt::local::Local; use rt::task::Task; use str::Str; @@ -85,7 +86,7 @@ pub extern "C" fn rust_stack_exhausted() { // #9854 - unwinding on windows through __morestack has never worked // #2361 - possible implementation of not using landing pads - let task: Option<~Task> = Local::try_take(); + let task: Option<Box<Task>> = Local::try_take(); let name = match task { Some(ref task) => { task.name.as_ref().map(|n| n.as_slice()) diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index ae5786604c7..5b29de5a8c1 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -24,6 +24,7 @@ use kinds::Send; use local_data; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use prelude::drop; use result::{Result, Ok, Err}; use rt::Runtime; @@ -51,19 +52,20 @@ pub struct Task { pub destroyed: bool, pub name: Option<SendStr>, - pub stdout: Option<~Writer:Send>, - pub stderr: Option<~Writer:Send>, + pub stdout: Option<Box<Writer:Send>>, + pub stderr: Option<Box<Writer:Send>>, - imp: Option<~Runtime:Send>, + imp: Option<Box<Runtime:Send>>, } pub struct GarbageCollector; pub struct LocalStorage(pub Option<local_data::Map>); -/// A handle to a blocked task. Usually this means having the ~Task pointer by -/// ownership, but if the task is killable, a killer can steal it at any time. +/// A handle to a blocked task. Usually this means having the Box<Task> +/// pointer by ownership, but if the task is killable, a killer can steal it +/// at any time. pub enum BlockedTask { - Owned(~Task), + Owned(Box<Task>), Shared(UnsafeArc<AtomicUint>), } @@ -109,12 +111,12 @@ impl Task { /// This function is *not* meant to be abused as a "try/catch" block. This /// is meant to be used at the absolute boundaries of a task's lifetime, and /// only for that purpose. - pub fn run(~self, mut f: ||) -> ~Task { + pub fn run(~self, mut f: ||) -> Box<Task> { // Need to put ourselves into TLS, but also need access to the unwinder. // Unsafely get a handle to the task so we can continue to use it after // putting it in tls (so we can invoke the unwinder). let handle: *mut Task = unsafe { - *cast::transmute::<&~Task, &*mut Task>(&self) + *cast::transmute::<&Box<Task>, &*mut Task>(&self) }; Local::put(self); @@ -187,7 +189,7 @@ impl Task { let me: *mut Task = Local::unsafe_borrow(); (*me).death.collect_failure((*me).unwinder.result()); } - let mut me: ~Task = Local::take(); + let mut me: Box<Task> = Local::take(); me.destroyed = true; return me; } @@ -195,7 +197,7 @@ impl Task { /// Inserts a runtime object into this task, transferring ownership to the /// task. It is illegal to replace a previous runtime object in this task /// with this argument. - pub fn put_runtime(&mut self, ops: ~Runtime:Send) { + pub fn put_runtime(&mut self, ops: Box<Runtime:Send>) { assert!(self.imp.is_none()); self.imp = Some(ops); } @@ -207,12 +209,12 @@ impl Task { /// /// It is recommended to only use this method when *absolutely necessary*. /// This function may not be available in the future. - pub fn maybe_take_runtime<T: 'static>(&mut self) -> Option<~T> { + pub fn maybe_take_runtime<T: 'static>(&mut self) -> Option<Box<T>> { // This is a terrible, terrible function. The general idea here is to - // take the runtime, cast it to ~Any, check if it has the right type, - // and then re-cast it back if necessary. The method of doing this is - // pretty sketchy and involves shuffling vtables of trait objects - // around, but it gets the job done. + // take the runtime, cast it to Box<Any>, check if it has the right + // type, and then re-cast it back if necessary. The method of doing + // this is pretty sketchy and involves shuffling vtables of trait + // objects around, but it gets the job done. // // FIXME: This function is a serious code smell and should be avoided at // all costs. I have yet to think of a method to avoid this @@ -225,7 +227,8 @@ impl Task { Ok(t) => Some(t), Err(t) => { let (_, obj): (uint, uint) = cast::transmute(t); - let obj: ~Runtime:Send = cast::transmute((vtable, obj)); + let obj: Box<Runtime:Send> = + cast::transmute((vtable, obj)); self.put_runtime(obj); None } @@ -308,7 +311,7 @@ impl Iterator<BlockedTask> for BlockedTasks { impl BlockedTask { /// Returns Some if the task was successfully woken; None if already killed. - pub fn wake(self) -> Option<~Task> { + pub fn wake(self) -> Option<Box<Task>> { match self { Owned(task) => Some(task), Shared(arc) => unsafe { @@ -326,7 +329,7 @@ impl BlockedTask { #[cfg(test)] pub fn trash(self) { assert!(self.wake().is_none()); } /// Create a blocked task, unless the task was already killed. - pub fn block(task: ~Task) -> BlockedTask { + pub fn block(task: Box<Task>) -> BlockedTask { Owned(task) } @@ -367,7 +370,7 @@ impl BlockedTask { if blocked_task_ptr & 0x1 == 0 { Owned(cast::transmute(blocked_task_ptr)) } else { - let ptr: ~UnsafeArc<AtomicUint> = + let ptr: Box<UnsafeArc<AtomicUint>> = cast::transmute(blocked_task_ptr & !1); Shared(*ptr) } diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index a836958279b..bc9a0b3460a 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -22,6 +22,7 @@ use kinds::Send; use libc; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use uint; type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; @@ -31,7 +32,7 @@ type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; pub struct Thread<T> { native: imp::rust_thread, joined: bool, - packet: ~Option<T>, + packet: Box<Option<T>>, } static DEFAULT_STACK_SIZE: uint = 1024 * 1024; @@ -45,7 +46,7 @@ extern fn thread_start(main: *libc::c_void) -> imp::rust_thread_return { use rt::stack; unsafe { stack::record_stack_bounds(0, uint::MAX); - let f: ~proc() = cast::transmute(main); + let f: Box<proc()> = cast::transmute(main); (*f)(); cast::transmute(0 as imp::rust_thread_return) } @@ -78,11 +79,11 @@ impl Thread<()> { pub fn start_stack<T: Send>(stack: uint, main: proc():Send -> T) -> Thread<T> { // We need the address of the packet to fill in to be stable so when - // `main` fills it in it's still valid, so allocate an extra ~ box to do + // `main` fills it in it's still valid, so allocate an extra box to do // so. let packet = box None; let packet2: *mut Option<T> = unsafe { - *cast::transmute::<&~Option<T>, **mut Option<T>>(&packet) + *cast::transmute::<&Box<Option<T>>, **mut Option<T>>(&packet) }; let main = proc() unsafe { *packet2 = Some(main()); }; let native = unsafe { imp::create(stack, box main) }; @@ -152,13 +153,14 @@ mod imp { use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, SIZE_T, BOOL, LPVOID, DWORD, LPDWORD, HANDLE}; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = HANDLE; pub type rust_thread_return = DWORD; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread { let arg: *mut libc::c_void = cast::transmute(p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -175,7 +177,7 @@ mod imp { if ret as uint == 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box<proc():Send> = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } return ret; @@ -218,13 +220,14 @@ mod imp { use libc; use mem; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = libc::pthread_t; pub type rust_thread_return = *u8; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread { let mut native: libc::pthread_t = mem::uninit(); let mut attr: libc::pthread_attr_t = mem::uninit(); assert_eq!(pthread_attr_init(&mut attr), 0); @@ -257,7 +260,7 @@ mod imp { if ret != 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box<proc():Send> = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } native diff --git a/src/libstd/rt/thread_local_storage.rs b/src/libstd/rt/thread_local_storage.rs index fceff80e792..77062068636 100644 --- a/src/libstd/rt/thread_local_storage.rs +++ b/src/libstd/rt/thread_local_storage.rs @@ -10,6 +10,8 @@ #![allow(dead_code)] +#[cfg(test)] +use owned::Box; #[cfg(unix)] use libc::c_int; #[cfg(unix)] @@ -99,11 +101,11 @@ fn tls_smoke_test() { let value = box 20; create(&mut key); set(key, transmute(value)); - let value: ~int = transmute(get(key)); + let value: Box<int> = transmute(get(key)); assert_eq!(value, box 20); let value = box 30; set(key, transmute(value)); - let value: ~int = transmute(get(key)); + let value: Box<int> = transmute(get(key)); assert_eq!(value, box 30); } } diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 98623c35b78..3ba97f381ab 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -64,6 +64,7 @@ use fmt; use kinds::Send; use mem; use option::{Some, None, Option}; +use owned::Box; use prelude::drop; use ptr::RawPtr; use result::{Err, Ok}; @@ -78,7 +79,7 @@ use uw = rt::libunwind; pub struct Unwinder { unwinding: bool, - cause: Option<~Any:Send> + cause: Option<Box<Any:Send>> } impl Unwinder { @@ -128,7 +129,7 @@ impl Unwinder { } } - pub fn begin_unwind(&mut self, cause: ~Any:Send) -> ! { + pub fn begin_unwind(&mut self, cause: Box<Any:Send>) -> ! { rtdebug!("begin_unwind()"); self.unwinding = true; @@ -154,7 +155,8 @@ impl Unwinder { exception: *uw::_Unwind_Exception) { rtdebug!("exception_cleanup()"); unsafe { - let _: ~uw::_Unwind_Exception = cast::transmute(exception); + let _: Box<uw::_Unwind_Exception> = + cast::transmute(exception); } } } @@ -374,14 +376,16 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> ! /// Do this split took the LLVM IR line counts of `fn main() { fail!() /// }` from ~1900/3700 (-O/no opts) to 180/590. #[inline(never)] #[cold] // this is the slow path, please never inline this -fn begin_unwind_inner(msg: ~Any:Send, file: &'static str, line: uint) -> ! { +fn begin_unwind_inner(msg: Box<Any:Send>, + file: &'static str, + line: uint) -> ! { let mut task; { let msg_s = match msg.as_ref::<&'static str>() { Some(s) => *s, None => match msg.as_ref::<~str>() { Some(s) => s.as_slice(), - None => "~Any", + None => "Box<Any>", } }; @@ -392,7 +396,7 @@ fn begin_unwind_inner(msg: ~Any:Send, file: &'static str, line: uint) -> ! { // order to get some better diagnostics, we print on failure and // immediately abort the whole process if there is no local task // available. - let opt_task: Option<~Task> = Local::try_take(); + let opt_task: Option<Box<Task>> = Local::try_take(); task = match opt_task { Some(t) => t, None => { diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index d8c866ef44a..2ea6dc1afe6 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -2352,10 +2352,11 @@ impl<A> FromIterator<A> for ~[A] { #[cfg(test)] mod tests { use prelude::*; - use mem; - use slice::*; use cmp::*; + use mem; + use owned::Box; use rand::{Rng, task_rng}; + use slice::*; fn square(n: uint) -> uint { n * n } @@ -2738,8 +2739,8 @@ mod tests { let mut v2 = vec![box 1, box 2, box 3, box 3]; v2.dedup(); /* - * If the ~pointers were leaked or otherwise misused, valgrind and/or - * rustrt should raise errors. + * If the boxed pointers were leaked or otherwise misused, valgrind + * and/or rustrt should raise errors. */ } @@ -3117,7 +3118,7 @@ mod tests { struct S { f: Cell<int>, - boxes: (~int, Rc<int>) + boxes: (Box<int>, Rc<int>) } impl Clone for S { @@ -3566,13 +3567,7 @@ mod tests { } assert_eq!(cnt, 11); - let xs = vec![Foo, Foo, Foo]; - assert_eq!(format!("{:?}", xs.slice(0, 2).to_owned()), - "~[slice::tests::Foo, slice::tests::Foo]".to_owned()); - let xs: [Foo, ..3] = [Foo, Foo, Foo]; - assert_eq!(format!("{:?}", xs.slice(0, 2).to_owned()), - "~[slice::tests::Foo, slice::tests::Foo]".to_owned()); cnt = 0; for f in xs.iter() { assert!(*f == Foo); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 430f6326327..2a51de7ce5c 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -20,9 +20,9 @@ Rust. Each string must also be decorated with its ownership. This means that there are two common kinds of strings in Rust: * `~str` - This is an owned string. This type obeys all of the normal semantics - of the `~T` types, meaning that it has one, and only one, owner. This - type cannot be implicitly copied, and is moved out of when passed to - other functions. + of the `Box<T>` types, meaning that it has one, and only one, + owner. This type cannot be implicitly copied, and is moved out of + when passed to other functions. * `&str` - This is the borrowed string type. This type of string can only be created from the other kind of string. As the name "borrowed" diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 0cf975a4c1c..d277c514e44 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -26,6 +26,7 @@ use clone::Clone; use iter::Iterator; use kinds::Send; use ops::Drop; +use owned::Box; use ptr::RawPtr; use sync::atomics::{fence, AtomicUint, Relaxed, Acquire, Release}; use ty::Unsafe; @@ -157,7 +158,7 @@ impl<T> Drop for UnsafeArc<T>{ // happened before), and an "acquire" operation before deleting the object. // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html) fence(Acquire); - let _: ~ArcData<T> = cast::transmute(self.data); + let _: Box<ArcData<T>> = cast::transmute(self.data); } } } diff --git a/src/libstd/sync/atomics.rs b/src/libstd/sync/atomics.rs index a3c1c33f77c..2fba59c3233 100644 --- a/src/libstd/sync/atomics.rs +++ b/src/libstd/sync/atomics.rs @@ -88,7 +88,7 @@ //! } //! }); //! -//! shared_big_object.swap(~BigObject, SeqCst); +//! shared_big_object.swap(box BigObject, SeqCst); //! } //! ``` //! @@ -112,6 +112,7 @@ use cast; use std::kinds::marker; use option::{Option,Some,None}; use ops::Drop; +use owned::Box; use ty::Unsafe; /// An atomic boolean type. @@ -663,7 +664,7 @@ impl<T> AtomicPtr<T> { impl<T> AtomicOption<T> { /// Create a new `AtomicOption` - pub fn new(p: ~T) -> AtomicOption<T> { + pub fn new(p: Box<T>) -> AtomicOption<T> { unsafe { AtomicOption { p: Unsafe::new(cast::transmute(p)) } } } @@ -672,7 +673,7 @@ impl<T> AtomicOption<T> { /// Store a value, returning the old value #[inline] - pub fn swap(&self, val: ~T, order: Ordering) -> Option<~T> { + pub fn swap(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> { unsafe { let val = cast::transmute(val); @@ -687,7 +688,7 @@ impl<T> AtomicOption<T> { /// Remove the value, leaving the `AtomicOption` empty. #[inline] - pub fn take(&self, order: Ordering) -> Option<~T> { + pub fn take(&self, order: Ordering) -> Option<Box<T>> { unsafe { self.swap(cast::transmute(0), order) } } @@ -697,7 +698,7 @@ impl<T> AtomicOption<T> { /// the option was already `Some`, returns `Some` of the rejected /// value. #[inline] - pub fn fill(&self, val: ~T, order: Ordering) -> Option<~T> { + pub fn fill(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> { unsafe { let val = cast::transmute(val); let expected = cast::transmute(0); diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index 22ed66b708b..d06062f02ac 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -56,6 +56,7 @@ use libc; use mem; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use ptr; use ptr::RawPtr; use sync::arc::UnsafeArc; @@ -117,7 +118,7 @@ pub enum Stolen<T> { /// will only use this structure when allocating a new buffer or deallocating a /// previous one. pub struct BufferPool<T> { - pool: Exclusive<Vec<~Buffer<T>>>, + pool: Exclusive<Vec<Box<Buffer<T>>>>, } /// An internal buffer used by the chase-lev deque. This structure is actually @@ -154,7 +155,7 @@ impl<T: Send> BufferPool<T> { (Worker { deque: a }, Stealer { deque: b }) } - fn alloc(&mut self, bits: int) -> ~Buffer<T> { + fn alloc(&mut self, bits: int) -> Box<Buffer<T>> { unsafe { self.pool.with(|pool| { match pool.iter().position(|x| x.size() >= (1 << bits)) { @@ -165,7 +166,7 @@ impl<T: Send> BufferPool<T> { } } - fn free(&mut self, buf: ~Buffer<T>) { + fn free(&mut self, buf: Box<Buffer<T>>) { unsafe { let mut buf = Some(buf); self.pool.with(|pool| { @@ -400,6 +401,7 @@ mod tests { use super::{Data, BufferPool, Abort, Empty, Worker, Stealer}; use cast; + use owned::Box; use rt::thread::Thread; use rand; use rand::Rng; @@ -471,7 +473,7 @@ mod tests { t.join(); } - fn stampede(mut w: Worker<~int>, s: Stealer<~int>, + fn stampede(mut w: Worker<Box<int>>, s: Stealer<Box<int>>, nthreads: int, amt: uint) { for _ in range(0, amt) { w.push(box 20); @@ -486,7 +488,7 @@ mod tests { let mut s = s; while (*unsafe_remaining).load(SeqCst) > 0 { match s.steal() { - Data(~20) => { + Data(box 20) => { (*unsafe_remaining).fetch_sub(1, SeqCst); } Data(..) => fail!(), @@ -499,7 +501,7 @@ mod tests { while remaining.load(SeqCst) > 0 { match w.pop() { - Some(~20) => { remaining.fetch_sub(1, SeqCst); } + Some(box 20) => { remaining.fetch_sub(1, SeqCst); } Some(..) => fail!(), None => {} } @@ -512,7 +514,7 @@ mod tests { #[test] fn run_stampede() { - let mut pool = BufferPool::<~int>::new(); + let mut pool = BufferPool::<Box<int>>::new(); let (w, s) = pool.deque(); stampede(w, s, 8, 10000); } @@ -520,7 +522,7 @@ mod tests { #[test] fn many_stampede() { static AMT: uint = 4; - let mut pool = BufferPool::<~int>::new(); + let mut pool = BufferPool::<Box<int>>::new(); let threads = range(0, AMT).map(|_| { let (w, s) = pool.deque(); Thread::start(proc() { @@ -605,7 +607,8 @@ mod tests { let s = s.clone(); let unique_box = box AtomicUint::new(0); let thread_box = unsafe { - *cast::transmute::<&~AtomicUint,**mut AtomicUint>(&unique_box) + *cast::transmute::<&Box<AtomicUint>, + **mut AtomicUint>(&unique_box) }; (Thread::start(proc() { unsafe { diff --git a/src/libstd/sync/mpsc_queue.rs b/src/libstd/sync/mpsc_queue.rs index 315e412446d..e05959e2591 100644 --- a/src/libstd/sync/mpsc_queue.rs +++ b/src/libstd/sync/mpsc_queue.rs @@ -42,6 +42,7 @@ use cast; use kinds::Send; use ops::Drop; use option::{Option, None, Some}; +use owned::Box; use ptr::RawPtr; use sync::atomics::{AtomicPtr, Release, Acquire, AcqRel, Relaxed}; @@ -120,7 +121,7 @@ impl<T: Send> Queue<T> { assert!((*tail).value.is_none()); assert!((*next).value.is_some()); let ret = (*next).value.take_unwrap(); - let _: ~Node<T> = cast::transmute(tail); + let _: Box<Node<T>> = cast::transmute(tail); return Data(ret); } @@ -145,7 +146,7 @@ impl<T: Send> Drop for Queue<T> { let mut cur = self.tail; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _: ~Node<T> = cast::transmute(cur); + let _: Box<Node<T>> = cast::transmute(cur); cur = next; } } diff --git a/src/libstd/sync/spsc_queue.rs b/src/libstd/sync/spsc_queue.rs index f155bdca446..7854a0e168e 100644 --- a/src/libstd/sync/spsc_queue.rs +++ b/src/libstd/sync/spsc_queue.rs @@ -37,6 +37,7 @@ use cast; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use ptr::RawPtr; use sync::atomics::{AtomicPtr, Relaxed, AtomicUint, Acquire, Release}; @@ -187,7 +188,7 @@ impl<T: Send> Queue<T> { (*self.tail_prev.load(Relaxed)).next.store(next, Relaxed); // We have successfully erased all references to 'tail', so // now we can safely drop it. - let _: ~Node<T> = cast::transmute(tail); + let _: Box<Node<T>> = cast::transmute(tail); } } return ret; @@ -215,7 +216,7 @@ impl<T: Send> Drop for Queue<T> { let mut cur = self.first; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _n: ~Node<T> = cast::transmute(cur); + let _n: Box<Node<T>> = cast::transmute(cur); cur = next; } } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index e9b01063f94..7c5e984ad36 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -41,6 +41,7 @@ use comm::{Sender, Receiver, channel}; use io::Writer; use kinds::{Send, marker}; use option::{None, Some, Option}; +use owned::Box; use result::{Result, Ok, Err}; use rt::local::Local; use rt::task::Task; @@ -56,7 +57,7 @@ use str::{Str, SendStr, IntoMaybeOwned}; /// /// If you wish for this result's delivery to block until all /// children tasks complete, recommend using a result future. -pub type TaskResult = Result<(), ~Any:Send>; +pub type TaskResult = Result<(), Box<Any:Send>>; /// Task configuration options pub struct TaskOpts { @@ -67,9 +68,9 @@ pub struct TaskOpts { /// The size of the stack for the spawned task pub stack_size: Option<uint>, /// Task-local stdout - pub stdout: Option<~Writer:Send>, + pub stdout: Option<Box<Writer:Send>>, /// Task-local stderr - pub stderr: Option<~Writer:Send>, + pub stderr: Option<Box<Writer:Send>>, } /** @@ -173,7 +174,7 @@ impl TaskBuilder { Some(gen) => gen(f), None => f }; - let t: ~Task = Local::take(); + let t: Box<Task> = Local::take(); t.spawn_sibling(self.opts, f); } @@ -190,7 +191,8 @@ impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - pub fn try<T:Send>(mut self, f: proc():Send -> T) -> Result<T, ~Any:Send> { + pub fn try<T:Send>(mut self, f: proc():Send -> T) + -> Result<T, Box<Any:Send>> { let (tx, rx) = channel(); let result = self.future_result(); @@ -240,7 +242,7 @@ pub fn spawn(f: proc():Send) { /// the function or an error if the task failed /// /// This is equivalent to TaskBuilder::new().try -pub fn try<T:Send>(f: proc():Send -> T) -> Result<T, ~Any:Send> { +pub fn try<T:Send>(f: proc():Send -> T) -> Result<T, Box<Any:Send>> { TaskBuilder::new().try(f) } @@ -264,7 +266,7 @@ pub fn deschedule() { use rt::local::Local; // FIXME(#7544): Optimize this, since we know we won't block. - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); task.yield_now(); } @@ -507,10 +509,10 @@ fn test_try_fail_message_owned_str() { #[test] fn test_try_fail_message_any() { match try(proc() { - fail!(box 413u16 as ~Any:Send); + fail!(box 413u16 as Box<Any:Send>); }) { Err(e) => { - type T = ~Any:Send; + type T = Box<Any:Send>; assert!(e.is::<T>()); let any = e.move::<T>().unwrap(); assert!(any.is::<u16>()); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index e264615578e..f0f126bcf16 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -971,9 +971,9 @@ impl<T> Vec<T> { /// # Example /// /// ```rust - /// let mut vec = vec!(~1); - /// vec.push_all_move(vec!(~2, ~3, ~4)); - /// assert_eq!(vec, vec!(~1, ~2, ~3, ~4)); + /// let mut vec = vec!(box 1); + /// vec.push_all_move(vec!(box 2, box 3, box 4)); + /// assert_eq!(vec, vec!(box 1, box 2, box 3, box 4)); /// ``` pub fn push_all_move(&mut self, other: Vec<T>) { self.extend(other.move_iter()); |
