Replace most ~exprs with 'box'. #11779
This commit is contained in:
parent
a67307e2a5
commit
a5be12ce7e
117 changed files with 630 additions and 623 deletions
|
@ -517,7 +517,7 @@ mod tests {
|
|||
#[bench]
|
||||
pub fn bench_copy_nonarena(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~Point {
|
||||
box Point {
|
||||
x: 1,
|
||||
y: 2,
|
||||
z: 3,
|
||||
|
@ -569,7 +569,7 @@ mod tests {
|
|||
#[bench]
|
||||
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~Noncopy {
|
||||
box Noncopy {
|
||||
string: "hello world".to_owned(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
}
|
||||
|
|
|
@ -377,8 +377,8 @@ impl<K: Clone + TotalOrd, V: Clone> Leaf<K, V> {
|
|||
== Less);
|
||||
let branch_return = Node::new_branch(vec!(BranchElt::new(midpoint.key.clone(),
|
||||
midpoint.value.clone(),
|
||||
~Node::new_leaf(left_leaf))),
|
||||
~Node::new_leaf(right_leaf));
|
||||
box Node::new_leaf(left_leaf))),
|
||||
box Node::new_leaf(right_leaf));
|
||||
return (branch_return, true);
|
||||
}
|
||||
(Node::new_leaf(self.elts.clone()), true)
|
||||
|
@ -540,10 +540,10 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
|
|||
//so we can return false.
|
||||
LeafNode(..) => {
|
||||
if index.unwrap() == self.elts.len() {
|
||||
self.rightmost_child = ~new_branch.clone();
|
||||
self.rightmost_child = box new_branch.clone();
|
||||
}
|
||||
else {
|
||||
self.elts.get_mut(index.unwrap()).left = ~new_branch.clone();
|
||||
self.elts.get_mut(index.unwrap()).left = box new_branch.clone();
|
||||
}
|
||||
return (Node::new_branch(self.clone().elts,
|
||||
self.clone().rightmost_child),
|
||||
|
@ -561,10 +561,10 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
|
|||
//and return it, saying we have inserted a new element.
|
||||
LeafNode(..) => {
|
||||
if index.unwrap() == self.elts.len() {
|
||||
self.rightmost_child = ~new_branch;
|
||||
self.rightmost_child = box new_branch;
|
||||
}
|
||||
else {
|
||||
self.elts.get_mut(index.unwrap()).left = ~new_branch;
|
||||
self.elts.get_mut(index.unwrap()).left = box new_branch;
|
||||
}
|
||||
return (Node::new_branch(self.clone().elts,
|
||||
self.clone().rightmost_child),
|
||||
|
@ -604,9 +604,9 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
|
|||
new_branch = Node::new_branch(
|
||||
vec!(BranchElt::new(midpoint.clone().key,
|
||||
midpoint.clone().value,
|
||||
~Node::new_branch(new_left,
|
||||
box Node::new_branch(new_left,
|
||||
midpoint.clone().left))),
|
||||
~Node::new_branch(new_right, self.clone().rightmost_child));
|
||||
box Node::new_branch(new_right, self.clone().rightmost_child));
|
||||
return (new_branch, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ impl<T> Deque<T> for DList<T> {
|
|||
///
|
||||
/// O(1)
|
||||
fn push_front(&mut self, elt: T) {
|
||||
self.push_front_node(~Node::new(elt))
|
||||
self.push_front_node(box Node::new(elt))
|
||||
}
|
||||
|
||||
/// Remove the first element and return it, or None if the list is empty
|
||||
|
@ -252,7 +252,7 @@ impl<T> Deque<T> for DList<T> {
|
|||
///
|
||||
/// O(1)
|
||||
fn push_back(&mut self, elt: T) {
|
||||
self.push_back_node(~Node::new(elt))
|
||||
self.push_back_node(box Node::new(elt))
|
||||
}
|
||||
|
||||
/// Remove the last element and return it, or None if the list is empty
|
||||
|
@ -555,7 +555,7 @@ impl<'a, A> MutItems<'a, A> {
|
|||
impl<'a, A> ListInsertion<A> for MutItems<'a, A> {
|
||||
#[inline]
|
||||
fn insert_next(&mut self, elt: A) {
|
||||
self.insert_next_node(~Node::new(elt))
|
||||
self.insert_next_node(box Node::new(elt))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -675,19 +675,19 @@ mod tests {
|
|||
assert_eq!(m.pop_front(), None);
|
||||
assert_eq!(m.pop_back(), None);
|
||||
assert_eq!(m.pop_front(), None);
|
||||
m.push_front(~1);
|
||||
m.push_front(box 1);
|
||||
assert_eq!(m.pop_front(), Some(~1));
|
||||
m.push_back(~2);
|
||||
m.push_back(~3);
|
||||
m.push_back(box 2);
|
||||
m.push_back(box 3);
|
||||
assert_eq!(m.len(), 2);
|
||||
assert_eq!(m.pop_front(), Some(~2));
|
||||
assert_eq!(m.pop_front(), Some(~3));
|
||||
assert_eq!(m.len(), 0);
|
||||
assert_eq!(m.pop_front(), None);
|
||||
m.push_back(~1);
|
||||
m.push_back(~3);
|
||||
m.push_back(~5);
|
||||
m.push_back(~7);
|
||||
m.push_back(box 1);
|
||||
m.push_back(box 3);
|
||||
m.push_back(box 5);
|
||||
m.push_back(box 7);
|
||||
assert_eq!(m.pop_front(), Some(~1));
|
||||
|
||||
let mut n = DList::new();
|
||||
|
|
|
@ -93,7 +93,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
|
|||
let cache = LruCache {
|
||||
map: HashMap::new(),
|
||||
max_size: capacity,
|
||||
head: unsafe{ cast::transmute(~mem::uninit::<LruEntry<K, V>>()) },
|
||||
head: unsafe{ cast::transmute(box mem::uninit::<LruEntry<K, V>>()) },
|
||||
};
|
||||
unsafe {
|
||||
(*cache.head).next = cache.head;
|
||||
|
@ -111,7 +111,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
|
|||
(node_ptr, None)
|
||||
}
|
||||
None => {
|
||||
let mut node = ~LruEntry::new(k, v);
|
||||
let mut node = box LruEntry::new(k, v);
|
||||
let node_ptr: *mut LruEntry<K, V> = &mut *node;
|
||||
(node_ptr, Some(node))
|
||||
}
|
||||
|
|
|
@ -273,19 +273,19 @@ mod tests {
|
|||
let mut heap = PriorityQueue::from_vec(vec!(~2, ~4, ~9));
|
||||
assert_eq!(heap.len(), 3);
|
||||
assert!(*heap.top() == ~9);
|
||||
heap.push(~11);
|
||||
heap.push(box 11);
|
||||
assert_eq!(heap.len(), 4);
|
||||
assert!(*heap.top() == ~11);
|
||||
heap.push(~5);
|
||||
heap.push(box 5);
|
||||
assert_eq!(heap.len(), 5);
|
||||
assert!(*heap.top() == ~11);
|
||||
heap.push(~27);
|
||||
heap.push(box 27);
|
||||
assert_eq!(heap.len(), 6);
|
||||
assert!(*heap.top() == ~27);
|
||||
heap.push(~3);
|
||||
heap.push(box 3);
|
||||
assert_eq!(heap.len(), 7);
|
||||
assert!(*heap.top() == ~27);
|
||||
heap.push(~103);
|
||||
heap.push(box 103);
|
||||
assert_eq!(heap.len(), 8);
|
||||
assert!(*heap.top() == ~103);
|
||||
}
|
||||
|
|
|
@ -459,7 +459,7 @@ mod test_map {
|
|||
#[test]
|
||||
fn test_move_iter() {
|
||||
let mut m = SmallIntMap::new();
|
||||
m.insert(1, ~2);
|
||||
m.insert(1, box 2);
|
||||
let mut called = false;
|
||||
for (k, v) in m.move_iter() {
|
||||
assert!(!called);
|
||||
|
@ -468,7 +468,7 @@ mod test_map {
|
|||
assert_eq!(v, ~2);
|
||||
}
|
||||
assert!(called);
|
||||
m.insert(2, ~1);
|
||||
m.insert(2, box 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -834,7 +834,7 @@ fn insert<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
|
|||
}
|
||||
}
|
||||
None => {
|
||||
*node = Some(~TreeNode::new(key, value));
|
||||
*node = Some(box TreeNode::new(key, value));
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -448,7 +448,7 @@ fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T,
|
|||
// have to move out of `child`.
|
||||
match mem::replace(child, Nothing) {
|
||||
External(stored_key, stored_value) => {
|
||||
let mut new = ~TrieNode::new();
|
||||
let mut new = box TrieNode::new();
|
||||
insert(&mut new.count,
|
||||
&mut new.children[chunk(stored_key, idx)],
|
||||
stored_key, stored_value, idx + 1);
|
||||
|
|
|
@ -23,7 +23,7 @@ use std::unstable::sync::Exclusive;
|
|||
|
||||
/// This is the only exported function from this module.
|
||||
pub fn event_loop() -> ~EventLoop:Send {
|
||||
~BasicLoop::new() as ~EventLoop:Send
|
||||
box BasicLoop::new() as ~EventLoop:Send
|
||||
}
|
||||
|
||||
struct BasicLoop {
|
||||
|
@ -143,7 +143,7 @@ impl EventLoop for BasicLoop {
|
|||
fn pausable_idle_callback(&mut self, cb: ~Callback:Send)
|
||||
-> ~PausableIdleCallback:Send
|
||||
{
|
||||
let callback = ~BasicPausable::new(self, cb);
|
||||
let callback = box BasicPausable::new(self, cb);
|
||||
rtassert!(self.idle.is_none());
|
||||
unsafe {
|
||||
let cb_ptr: &*mut BasicPausable = cast::transmute(&callback);
|
||||
|
@ -156,7 +156,7 @@ impl EventLoop for BasicLoop {
|
|||
let id = self.next_remote;
|
||||
self.next_remote += 1;
|
||||
self.remotes.push((id, f));
|
||||
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback:Send
|
||||
box BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback:Send
|
||||
}
|
||||
|
||||
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> { None }
|
||||
|
|
|
@ -152,7 +152,7 @@ struct Registers {
|
|||
|
||||
#[cfg(target_arch = "x86")]
|
||||
fn new_regs() -> ~Registers {
|
||||
~Registers {
|
||||
box Registers {
|
||||
eax: 0, ebx: 0, ecx: 0, edx: 0,
|
||||
ebp: 0, esi: 0, edi: 0, esp: 0,
|
||||
cs: 0, ds: 0, ss: 0, es: 0, fs: 0, gs: 0,
|
||||
|
@ -190,9 +190,9 @@ type Registers = [uint, ..34];
|
|||
type Registers = [uint, ..22];
|
||||
|
||||
#[cfg(windows, target_arch = "x86_64")]
|
||||
fn new_regs() -> ~Registers { ~([0, .. 34]) }
|
||||
fn new_regs() -> ~Registers { box [0, .. 34] }
|
||||
#[cfg(not(windows), target_arch = "x86_64")]
|
||||
fn new_regs() -> ~Registers { ~([0, .. 22]) }
|
||||
fn new_regs() -> ~Registers { box {let v = [0, .. 22]; v} }
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
|
||||
|
@ -241,7 +241,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
|
|||
type Registers = [uint, ..32];
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
fn new_regs() -> ~Registers { ~([0, .. 32]) }
|
||||
fn new_regs() -> ~Registers { box {[0, .. 32]} }
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
|
||||
|
@ -270,7 +270,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
|
|||
type Registers = [uint, ..32];
|
||||
|
||||
#[cfg(target_arch = "mips")]
|
||||
fn new_regs() -> ~Registers { ~([0, .. 32]) }
|
||||
fn new_regs() -> ~Registers { box [0, .. 32] }
|
||||
|
||||
#[cfg(target_arch = "mips")]
|
||||
fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
|
||||
|
|
|
@ -427,7 +427,7 @@ impl SchedPool {
|
|||
for worker in workers.move_iter() {
|
||||
rtdebug!("inserting a regular scheduler");
|
||||
|
||||
let mut sched = ~Scheduler::new(pool.id,
|
||||
let mut sched = box Scheduler::new(pool.id,
|
||||
(pool.factory)(),
|
||||
worker,
|
||||
pool.stealers.clone(),
|
||||
|
@ -488,7 +488,7 @@ impl SchedPool {
|
|||
// Create the new scheduler, using the same sleeper list as all the
|
||||
// other schedulers as well as having a stealer handle to all other
|
||||
// schedulers.
|
||||
let mut sched = ~Scheduler::new(self.id,
|
||||
let mut sched = box Scheduler::new(self.id,
|
||||
(self.factory)(),
|
||||
worker,
|
||||
self.stealers.clone(),
|
||||
|
|
|
@ -183,7 +183,7 @@ impl Scheduler {
|
|||
pub fn bootstrap(mut ~self) {
|
||||
|
||||
// Build an Idle callback.
|
||||
let cb = ~SchedRunner as ~Callback:Send;
|
||||
let cb = box SchedRunner as ~Callback:Send;
|
||||
self.idle_callback = Some(self.event_loop.pausable_idle_callback(cb));
|
||||
|
||||
// Create a task for the scheduler with an empty context.
|
||||
|
@ -869,7 +869,7 @@ impl Scheduler {
|
|||
}
|
||||
|
||||
pub fn make_handle(&mut self) -> SchedHandle {
|
||||
let remote = self.event_loop.remote_callback(~SchedRunner);
|
||||
let remote = self.event_loop.remote_callback(box SchedRunner);
|
||||
|
||||
return SchedHandle {
|
||||
remote: remote,
|
||||
|
@ -1140,7 +1140,7 @@ mod test {
|
|||
let (_p, state) = TaskState::new();
|
||||
|
||||
// Our normal scheduler
|
||||
let mut normal_sched = ~Scheduler::new(
|
||||
let mut normal_sched = box Scheduler::new(
|
||||
1,
|
||||
basic::event_loop(),
|
||||
normal_worker,
|
||||
|
@ -1152,7 +1152,7 @@ mod test {
|
|||
let friend_handle = normal_sched.make_handle();
|
||||
|
||||
// Our special scheduler
|
||||
let mut special_sched = ~Scheduler::new_special(
|
||||
let mut special_sched = box Scheduler::new_special(
|
||||
1,
|
||||
basic::event_loop(),
|
||||
special_worker,
|
||||
|
@ -1403,7 +1403,7 @@ mod test {
|
|||
|
||||
impl Drop for S {
|
||||
fn drop(&mut self) {
|
||||
let _foo = ~0;
|
||||
let _foo = box 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,8 +82,8 @@ impl Runtime for SimpleTask {
|
|||
}
|
||||
|
||||
pub fn task() -> ~Task {
|
||||
let mut task = ~Task::new();
|
||||
task.put_runtime(~SimpleTask {
|
||||
let mut task = box Task::new();
|
||||
task.put_runtime(box SimpleTask {
|
||||
lock: unsafe {NativeMutex::new()},
|
||||
awoken: false,
|
||||
});
|
||||
|
|
|
@ -159,14 +159,14 @@ impl GreenTask {
|
|||
/// useful when creating scheduler tasks.
|
||||
pub fn new_typed(coroutine: Option<Coroutine>,
|
||||
task_type: TaskType) -> ~GreenTask {
|
||||
~GreenTask {
|
||||
box GreenTask {
|
||||
pool_id: 0,
|
||||
coroutine: coroutine,
|
||||
task_type: task_type,
|
||||
sched: None,
|
||||
handle: None,
|
||||
nasty_deschedule_lock: unsafe { NativeMutex::new() },
|
||||
task: Some(~Task::new()),
|
||||
task: Some(box Task::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ pub fn log(level: u32, args: &fmt::Arguments) {
|
|||
// frob the slot while we're doing the logging. This will destroy any logger
|
||||
// set during logging.
|
||||
let mut logger = local_data::pop(local_logger).unwrap_or_else(|| {
|
||||
~DefaultLogger { handle: io::stderr() } as ~Logger:Send
|
||||
box DefaultLogger { handle: io::stderr() } as ~Logger:Send
|
||||
});
|
||||
logger.log(level, args);
|
||||
local_data::set(local_logger, logger);
|
||||
|
@ -286,7 +286,7 @@ fn init() {
|
|||
LOG_LEVEL = max_level;
|
||||
|
||||
assert!(DIRECTIVES.is_null());
|
||||
DIRECTIVES = cast::transmute(~directives);
|
||||
DIRECTIVES = cast::transmute(box directives);
|
||||
|
||||
// Schedule the cleanup for this global for when the runtime exits.
|
||||
rt::at_exit(proc() {
|
||||
|
|
|
@ -176,7 +176,7 @@ impl rtio::RtioPipe for FileDesc {
|
|||
self.inner_write(buf)
|
||||
}
|
||||
fn clone(&self) -> ~rtio::RtioPipe:Send {
|
||||
~FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
|
||||
box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ impl rtio::RtioPipe for FileDesc {
|
|||
self.inner_write(buf)
|
||||
}
|
||||
fn clone(&self) -> ~rtio::RtioPipe:Send {
|
||||
~FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
|
||||
box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -167,20 +167,20 @@ impl rtio::IoFactory for IoFactory {
|
|||
// networking
|
||||
fn tcp_connect(&mut self, addr: SocketAddr,
|
||||
timeout: Option<u64>) -> IoResult<~RtioTcpStream:Send> {
|
||||
net::TcpStream::connect(addr, timeout).map(|s| ~s as ~RtioTcpStream:Send)
|
||||
net::TcpStream::connect(addr, timeout).map(|s| box s as ~RtioTcpStream:Send)
|
||||
}
|
||||
fn tcp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioTcpListener:Send> {
|
||||
net::TcpListener::bind(addr).map(|s| ~s as ~RtioTcpListener:Send)
|
||||
net::TcpListener::bind(addr).map(|s| box s as ~RtioTcpListener:Send)
|
||||
}
|
||||
fn udp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioUdpSocket:Send> {
|
||||
net::UdpSocket::bind(addr).map(|u| ~u as ~RtioUdpSocket:Send)
|
||||
net::UdpSocket::bind(addr).map(|u| box u as ~RtioUdpSocket:Send)
|
||||
}
|
||||
fn unix_bind(&mut self, path: &CString) -> IoResult<~RtioUnixListener:Send> {
|
||||
pipe::UnixListener::bind(path).map(|s| ~s as ~RtioUnixListener:Send)
|
||||
pipe::UnixListener::bind(path).map(|s| box s as ~RtioUnixListener:Send)
|
||||
}
|
||||
fn unix_connect(&mut self, path: &CString,
|
||||
timeout: Option<u64>) -> IoResult<~RtioPipe:Send> {
|
||||
pipe::UnixStream::connect(path, timeout).map(|s| ~s as ~RtioPipe:Send)
|
||||
pipe::UnixStream::connect(path, timeout).map(|s| box s as ~RtioPipe:Send)
|
||||
}
|
||||
fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>,
|
||||
hint: Option<ai::Hint>) -> IoResult<~[ai::Info]> {
|
||||
|
@ -194,11 +194,11 @@ impl rtio::IoFactory for IoFactory {
|
|||
rtio::CloseSynchronously | rtio::CloseAsynchronously => true,
|
||||
rtio::DontClose => false
|
||||
};
|
||||
~file::FileDesc::new(fd, close) as ~RtioFileStream:Send
|
||||
box file::FileDesc::new(fd, close) as ~RtioFileStream:Send
|
||||
}
|
||||
fn fs_open(&mut self, path: &CString, fm: io::FileMode, fa: io::FileAccess)
|
||||
-> IoResult<~RtioFileStream:Send> {
|
||||
file::open(path, fm, fa).map(|fd| ~fd as ~RtioFileStream:Send)
|
||||
file::open(path, fm, fa).map(|fd| box fd as ~RtioFileStream:Send)
|
||||
}
|
||||
fn fs_unlink(&mut self, path: &CString) -> IoResult<()> {
|
||||
file::unlink(path)
|
||||
|
@ -245,26 +245,26 @@ impl rtio::IoFactory for IoFactory {
|
|||
|
||||
// misc
|
||||
fn timer_init(&mut self) -> IoResult<~RtioTimer:Send> {
|
||||
timer::Timer::new().map(|t| ~t as ~RtioTimer:Send)
|
||||
timer::Timer::new().map(|t| box t as ~RtioTimer:Send)
|
||||
}
|
||||
fn spawn(&mut self, config: ProcessConfig)
|
||||
-> IoResult<(~RtioProcess:Send, ~[Option<~RtioPipe:Send>])> {
|
||||
process::Process::spawn(config).map(|(p, io)| {
|
||||
(~p as ~RtioProcess:Send,
|
||||
io.move_iter().map(|p| p.map(|p| ~p as ~RtioPipe:Send)).collect())
|
||||
(box p as ~RtioProcess:Send,
|
||||
io.move_iter().map(|p| p.map(|p| box p as ~RtioPipe:Send)).collect())
|
||||
})
|
||||
}
|
||||
fn kill(&mut self, pid: libc::pid_t, signum: int) -> IoResult<()> {
|
||||
process::Process::kill(pid, signum)
|
||||
}
|
||||
fn pipe_open(&mut self, fd: c_int) -> IoResult<~RtioPipe:Send> {
|
||||
Ok(~file::FileDesc::new(fd, true) as ~RtioPipe:Send)
|
||||
Ok(box file::FileDesc::new(fd, true) as ~RtioPipe:Send)
|
||||
}
|
||||
fn tty_open(&mut self, fd: c_int, _readable: bool)
|
||||
-> IoResult<~RtioTTY:Send>
|
||||
{
|
||||
if unsafe { libc::isatty(fd) } != 0 {
|
||||
Ok(~file::FileDesc::new(fd, true) as ~RtioTTY:Send)
|
||||
Ok(box file::FileDesc::new(fd, true) as ~RtioTTY:Send)
|
||||
} else {
|
||||
Err(IoError {
|
||||
kind: io::MismatchedFileTypeForOperation,
|
||||
|
|
|
@ -352,7 +352,7 @@ impl rtio::RtioTcpStream for TcpStream {
|
|||
}
|
||||
|
||||
fn clone(&self) -> ~rtio::RtioTcpStream:Send {
|
||||
~TcpStream { inner: self.inner.clone() } as ~rtio::RtioTcpStream:Send
|
||||
box TcpStream { inner: self.inner.clone() } as ~rtio::RtioTcpStream:Send
|
||||
}
|
||||
fn close_write(&mut self) -> IoResult<()> {
|
||||
super::mkerr_libc(unsafe {
|
||||
|
@ -419,7 +419,7 @@ impl TcpListener {
|
|||
|
||||
impl rtio::RtioTcpListener for TcpListener {
|
||||
fn listen(~self) -> IoResult<~rtio::RtioTcpAcceptor:Send> {
|
||||
self.native_listen(128).map(|a| ~a as ~rtio::RtioTcpAcceptor:Send)
|
||||
self.native_listen(128).map(|a| box a as ~rtio::RtioTcpAcceptor:Send)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,7 +466,7 @@ impl rtio::RtioSocket for TcpAcceptor {
|
|||
|
||||
impl rtio::RtioTcpAcceptor for TcpAcceptor {
|
||||
fn accept(&mut self) -> IoResult<~rtio::RtioTcpStream:Send> {
|
||||
self.native_accept().map(|s| ~s as ~rtio::RtioTcpStream:Send)
|
||||
self.native_accept().map(|s| box s as ~rtio::RtioTcpStream:Send)
|
||||
}
|
||||
|
||||
fn accept_simultaneously(&mut self) -> IoResult<()> { Ok(()) }
|
||||
|
@ -638,6 +638,6 @@ impl rtio::RtioUdpSocket for UdpSocket {
|
|||
}
|
||||
|
||||
fn clone(&self) -> ~rtio::RtioUdpSocket:Send {
|
||||
~UdpSocket { inner: self.inner.clone() } as ~rtio::RtioUdpSocket:Send
|
||||
box UdpSocket { inner: self.inner.clone() } as ~rtio::RtioUdpSocket:Send
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ impl rtio::RtioPipe for UnixStream {
|
|||
}
|
||||
|
||||
fn clone(&self) -> ~rtio::RtioPipe:Send {
|
||||
~UnixStream { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
|
||||
box UnixStream { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ impl UnixListener {
|
|||
|
||||
impl rtio::RtioUnixListener for UnixListener {
|
||||
fn listen(~self) -> IoResult<~rtio::RtioUnixAcceptor:Send> {
|
||||
self.native_listen(128).map(|a| ~a as ~rtio::RtioUnixAcceptor:Send)
|
||||
self.native_listen(128).map(|a| box a as ~rtio::RtioUnixAcceptor:Send)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ impl UnixAcceptor {
|
|||
|
||||
impl rtio::RtioUnixAcceptor for UnixAcceptor {
|
||||
fn accept(&mut self) -> IoResult<~rtio::RtioPipe:Send> {
|
||||
self.native_accept().map(|s| ~s as ~rtio::RtioPipe:Send)
|
||||
self.native_accept().map(|s| box s as ~rtio::RtioPipe:Send)
|
||||
}
|
||||
fn set_timeout(&mut self, timeout: Option<u64>) {
|
||||
self.deadline = timeout.map(|a| ::io::timer::now() + a).unwrap_or(0);
|
||||
|
|
|
@ -354,7 +354,7 @@ impl rtio::RtioPipe for UnixStream {
|
|||
}
|
||||
|
||||
fn clone(&self) -> ~rtio::RtioPipe:Send {
|
||||
~UnixStream {
|
||||
box UnixStream {
|
||||
inner: self.inner.clone(),
|
||||
read: None,
|
||||
write: None,
|
||||
|
@ -403,7 +403,7 @@ impl Drop for UnixListener {
|
|||
|
||||
impl rtio::RtioUnixListener for UnixListener {
|
||||
fn listen(~self) -> IoResult<~rtio::RtioUnixAcceptor:Send> {
|
||||
self.native_listen().map(|a| ~a as ~rtio::RtioUnixAcceptor:Send)
|
||||
self.native_listen().map(|a| box a as ~rtio::RtioUnixAcceptor:Send)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -527,7 +527,7 @@ impl UnixAcceptor {
|
|||
|
||||
impl rtio::RtioUnixAcceptor for UnixAcceptor {
|
||||
fn accept(&mut self) -> IoResult<~rtio::RtioPipe:Send> {
|
||||
self.native_accept().map(|s| ~s as ~rtio::RtioPipe:Send)
|
||||
self.native_accept().map(|s| box s as ~rtio::RtioPipe:Send)
|
||||
}
|
||||
fn set_timeout(&mut self, timeout: Option<u64>) {
|
||||
self.deadline = timeout.map(|i| i + ::io::timer::now()).unwrap_or(0);
|
||||
|
|
|
@ -48,7 +48,7 @@ pub fn boot(helper: fn(imp::signal, Receiver<Req>)) {
|
|||
let (tx, rx) = channel();
|
||||
// promote this to a shared channel
|
||||
drop(tx.clone());
|
||||
HELPER_CHAN = cast::transmute(~tx);
|
||||
HELPER_CHAN = cast::transmute(box tx);
|
||||
let (receive, send) = imp::new();
|
||||
HELPER_SIGNAL = send;
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ impl Timer {
|
|||
let id = unsafe { ID.fetch_add(1, atomics::Relaxed) };
|
||||
Ok(Timer {
|
||||
id: id,
|
||||
inner: Some(~Inner {
|
||||
inner: Some(box Inner {
|
||||
tx: None,
|
||||
interval: 0,
|
||||
target: 0,
|
||||
|
|
|
@ -32,7 +32,7 @@ use task;
|
|||
|
||||
/// Creates a new Task which is ready to execute as a 1:1 task.
|
||||
pub fn new(stack_bounds: (uint, uint)) -> ~Task {
|
||||
let mut task = ~Task::new();
|
||||
let mut task = box Task::new();
|
||||
let mut ops = ops();
|
||||
ops.stack_bounds = stack_bounds;
|
||||
task.put_runtime(ops);
|
||||
|
@ -40,7 +40,7 @@ pub fn new(stack_bounds: (uint, uint)) -> ~Task {
|
|||
}
|
||||
|
||||
fn ops() -> ~Ops {
|
||||
~Ops {
|
||||
box Ops {
|
||||
lock: unsafe { NativeMutex::new() },
|
||||
awoken: false,
|
||||
io: io::IoFactory::new(),
|
||||
|
@ -62,7 +62,7 @@ pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
|
|||
stderr, stdout,
|
||||
} = opts;
|
||||
|
||||
let mut task = ~Task::new();
|
||||
let mut task = box Task::new();
|
||||
task.name = name;
|
||||
task.stderr = stderr;
|
||||
task.stdout = stdout;
|
||||
|
|
|
@ -602,7 +602,7 @@ pub fn task_rng() -> TaskRng {
|
|||
Ok(r) => r,
|
||||
Err(e) => fail!("could not initialize task_rng: {}", e)
|
||||
};
|
||||
let mut rng = ~reseeding::ReseedingRng::new(r,
|
||||
let mut rng = box reseeding::ReseedingRng::new(r,
|
||||
TASK_RNG_RESEED_THRESHOLD,
|
||||
TaskRngReseeder);
|
||||
let ptr = &mut *rng as *mut TaskRngInner;
|
||||
|
|
|
@ -216,7 +216,7 @@ impl<T:Rand> Rand for Option<T> {
|
|||
|
||||
impl<T: Rand> Rand for ~T {
|
||||
#[inline]
|
||||
fn rand<R: Rng>(rng: &mut R) -> ~T { ~rng.gen() }
|
||||
fn rand<R: Rng>(rng: &mut R) -> ~T { box rng.gen() }
|
||||
}
|
||||
|
||||
impl<T: Rand + 'static> Rand for @T {
|
||||
|
|
|
@ -78,7 +78,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_reader_rng_u64() {
|
||||
// transmute from the target to avoid endianness concerns.
|
||||
let v = ~[1u64, 2u64, 3u64];
|
||||
let v = box [1u64, 2u64, 3u64];
|
||||
let bytes: ~[u8] = unsafe {cast::transmute(v)};
|
||||
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
|
||||
|
||||
|
@ -89,7 +89,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_reader_rng_u32() {
|
||||
// transmute from the target to avoid endianness concerns.
|
||||
let v = ~[1u32, 2u32, 3u32];
|
||||
let v = box [1u32, 2u32, 3u32];
|
||||
let bytes: ~[u8] = unsafe {cast::transmute(v)};
|
||||
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
|
||||
|
||||
|
|
|
@ -673,11 +673,11 @@ pub fn pretty_print_input(sess: Session,
|
|||
let mut rdr = MemReader::new(src);
|
||||
|
||||
let out = match ofile {
|
||||
None => ~io::stdout() as ~Writer,
|
||||
None => box io::stdout() as ~Writer,
|
||||
Some(p) => {
|
||||
let r = io::File::create(&p);
|
||||
match r {
|
||||
Ok(w) => ~w as ~Writer,
|
||||
Ok(w) => box w as ~Writer,
|
||||
Err(e) => fail!("print-print failed to open {} due to {}",
|
||||
p.display(), e),
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ pub fn monitor(f: proc():Send) {
|
|||
let mut r = io::ChanReader::new(rx);
|
||||
|
||||
match task_builder.try(proc() {
|
||||
io::stdio::set_stderr(~w);
|
||||
io::stdio::set_stderr(box w);
|
||||
f()
|
||||
}) {
|
||||
Ok(()) => { /* fallthrough */ }
|
||||
|
@ -425,7 +425,7 @@ pub fn monitor(f: proc():Send) {
|
|||
// Fail so the process returns a failure code, but don't pollute the
|
||||
// output with some unnecessary failure messages, we've already
|
||||
// printed everything that we needed to.
|
||||
io::stdio::set_stderr(~io::util::NullWriter);
|
||||
io::stdio::set_stderr(box io::util::NullWriter);
|
||||
fail!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ impl<'a, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, O> {
|
|||
|
||||
debug!("Dataflow result:");
|
||||
debug!("{}", {
|
||||
self.pretty_print_to(~io::stderr(), blk).unwrap();
|
||||
self.pretty_print_to(box io::stderr(), blk).unwrap();
|
||||
""
|
||||
});
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ impl<'a> MarkSymbolVisitor<'a> {
|
|||
MarkSymbolVisitor {
|
||||
worklist: worklist,
|
||||
tcx: tcx,
|
||||
live_symbols: ~HashSet::new(),
|
||||
live_symbols: box HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1922,7 +1922,7 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
|
|||
if ty::type_is_empty(tcx, t) {
|
||||
// Special case for empty types
|
||||
let fail_cx = Cell::new(None);
|
||||
let fail_handler = ~DynamicFailureHandler {
|
||||
let fail_handler = box DynamicFailureHandler {
|
||||
bcx: scope_cx,
|
||||
sp: discr_expr.span,
|
||||
msg: InternedString::new("scrutinizing value that can't \
|
||||
|
|
|
@ -236,7 +236,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
|
|||
*/
|
||||
|
||||
if !ty::type_needs_drop(self.ccx.tcx(), ty) { return; }
|
||||
let drop = ~DropValue {
|
||||
let drop = box DropValue {
|
||||
is_immediate: false,
|
||||
on_unwind: ty::type_needs_unwind_cleanup(self.ccx.tcx(), ty),
|
||||
val: val,
|
||||
|
@ -260,7 +260,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
|
|||
*/
|
||||
|
||||
if !ty::type_needs_drop(self.ccx.tcx(), ty) { return; }
|
||||
let drop = ~DropValue {
|
||||
let drop = box DropValue {
|
||||
is_immediate: true,
|
||||
on_unwind: ty::type_needs_unwind_cleanup(self.ccx.tcx(), ty),
|
||||
val: val,
|
||||
|
@ -284,7 +284,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
|
|||
* operation.
|
||||
*/
|
||||
|
||||
let drop = ~FreeValue { ptr: val, heap: heap };
|
||||
let drop = box FreeValue { ptr: val, heap: heap };
|
||||
|
||||
debug!("schedule_free_value({:?}, val={}, heap={:?})",
|
||||
cleanup_scope,
|
||||
|
|
|
@ -757,7 +757,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
|
|||
});
|
||||
|
||||
// Initialize fn debug context (including scope map and namespace map)
|
||||
let fn_debug_context = ~FunctionDebugContextData {
|
||||
let fn_debug_context = box FunctionDebugContextData {
|
||||
scope_map: RefCell::new(HashMap::new()),
|
||||
fn_metadata: fn_metadata,
|
||||
argument_counter: Cell::new(1),
|
||||
|
|
|
@ -1231,7 +1231,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
|
|||
}
|
||||
}
|
||||
|
||||
let t = ~t_box_ {
|
||||
let t = box t_box_ {
|
||||
sty: st,
|
||||
id: cx.next_id.get(),
|
||||
flags: flags,
|
||||
|
@ -1400,7 +1400,7 @@ pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t {
|
|||
pub fn mk_tup(cx: &ctxt, ts: Vec<t>) -> t { mk_t(cx, ty_tup(ts)) }
|
||||
|
||||
pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
|
||||
mk_t(cx, ty_closure(~fty))
|
||||
mk_t(cx, ty_closure(box fty))
|
||||
}
|
||||
|
||||
pub fn mk_bare_fn(cx: &ctxt, fty: BareFnTy) -> t {
|
||||
|
@ -1433,7 +1433,7 @@ pub fn mk_trait(cx: &ctxt,
|
|||
bounds: BuiltinBounds)
|
||||
-> t {
|
||||
// take a copy of substs so that we own the vectors inside
|
||||
let inner = ~TyTrait {
|
||||
let inner = box TyTrait {
|
||||
def_id: did,
|
||||
substs: substs,
|
||||
store: store,
|
||||
|
|
|
@ -150,7 +150,7 @@ pub fn super_fold_sty<T:TypeFolder>(this: &mut T,
|
|||
ty::ty_enum(tid, this.fold_substs(substs))
|
||||
}
|
||||
ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, bounds }) => {
|
||||
ty::ty_trait(~ty::TyTrait{
|
||||
ty::ty_trait(box ty::TyTrait{
|
||||
def_id: def_id,
|
||||
substs: this.fold_substs(substs),
|
||||
store: this.fold_trait_store(store),
|
||||
|
@ -164,7 +164,7 @@ pub fn super_fold_sty<T:TypeFolder>(this: &mut T,
|
|||
ty::ty_bare_fn(this.fold_bare_fn_ty(f))
|
||||
}
|
||||
ty::ty_closure(ref f) => {
|
||||
ty::ty_closure(~this.fold_closure_ty(*f))
|
||||
ty::ty_closure(box this.fold_closure_ty(*f))
|
||||
}
|
||||
ty::ty_rptr(r, ref tm) => {
|
||||
ty::ty_rptr(this.fold_region(r),
|
||||
|
|
|
@ -593,7 +593,7 @@ mod tests {
|
|||
|
||||
let tests = wikipedia_tests;
|
||||
|
||||
let mut sh = ~Sha256::new();
|
||||
let mut sh = box Sha256::new();
|
||||
|
||||
test_hash(sh, tests.as_slice());
|
||||
}
|
||||
|
|
|
@ -724,14 +724,14 @@ impl Clean<Type> for ast::Ty {
|
|||
debug!("span corresponds to `{}`", codemap.span_to_str(self.span));
|
||||
match self.node {
|
||||
TyNil => Unit,
|
||||
TyPtr(ref m) => RawPointer(m.mutbl.clean(), ~m.ty.clean()),
|
||||
TyPtr(ref m) => RawPointer(m.mutbl.clean(), box m.ty.clean()),
|
||||
TyRptr(ref l, ref m) =>
|
||||
BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
|
||||
type_: ~m.ty.clean()},
|
||||
TyBox(ty) => Managed(~ty.clean()),
|
||||
TyUniq(ty) => Unique(~ty.clean()),
|
||||
TyVec(ty) => Vector(~ty.clean()),
|
||||
TyFixedLengthVec(ty, ref e) => FixedVector(~ty.clean(),
|
||||
type_: box m.ty.clean()},
|
||||
TyBox(ty) => Managed(box ty.clean()),
|
||||
TyUniq(ty) => Unique(box ty.clean()),
|
||||
TyVec(ty) => Vector(box ty.clean()),
|
||||
TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(),
|
||||
e.span.to_src()),
|
||||
TyTup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()),
|
||||
TyPath(ref p, ref tpbs, id) => {
|
||||
|
@ -739,9 +739,9 @@ impl Clean<Type> for ast::Ty {
|
|||
tpbs.clean().map(|x| x.move_iter().collect()),
|
||||
id)
|
||||
}
|
||||
TyClosure(ref c, region) => Closure(~c.clean(), region.clean()),
|
||||
TyProc(ref c) => Proc(~c.clean()),
|
||||
TyBareFn(ref barefn) => BareFunction(~barefn.clean()),
|
||||
TyClosure(ref c, region) => Closure(box c.clean(), region.clean()),
|
||||
TyProc(ref c) => Proc(box c.clean()),
|
||||
TyBareFn(ref barefn) => BareFunction(box barefn.clean()),
|
||||
TyBot => Bottom,
|
||||
ref x => fail!("Unimplemented type {:?}", x),
|
||||
}
|
||||
|
|
|
@ -379,9 +379,9 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
|
|||
// "crate": { parsed crate ... },
|
||||
// "plugins": { output of plugins ... }
|
||||
// }
|
||||
let mut json = ~collections::TreeMap::new();
|
||||
let mut json = box collections::TreeMap::new();
|
||||
json.insert("schema".to_owned(), json::String(SCHEMA_VERSION.to_owned()));
|
||||
let plugins_json = ~res.move_iter().filter_map(|opt| opt).collect();
|
||||
let plugins_json = box res.move_iter().filter_map(|opt| opt).collect();
|
||||
|
||||
// FIXME #8335: yuck, Rust -> str -> JSON round trip! No way to .encode
|
||||
// straight to the Rust JSON representation.
|
||||
|
|
|
@ -123,17 +123,17 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
|
|||
let (tx, rx) = channel();
|
||||
let w1 = io::ChanWriter::new(tx);
|
||||
let w2 = w1.clone();
|
||||
let old = io::stdio::set_stderr(~w1);
|
||||
let old = io::stdio::set_stderr(box w1);
|
||||
spawn(proc() {
|
||||
let mut p = io::ChanReader::new(rx);
|
||||
let mut err = old.unwrap_or(~io::stderr() as ~Writer:Send);
|
||||
let mut err = old.unwrap_or(box io::stderr() as ~Writer:Send);
|
||||
io::util::copy(&mut p, &mut err).unwrap();
|
||||
});
|
||||
let emitter = diagnostic::EmitterWriter::new(~w2);
|
||||
let emitter = diagnostic::EmitterWriter::new(box w2);
|
||||
|
||||
// Compile the code
|
||||
let codemap = CodeMap::new();
|
||||
let diagnostic_handler = diagnostic::mk_handler(~emitter);
|
||||
let diagnostic_handler = diagnostic::mk_handler(box emitter);
|
||||
let span_diagnostic_handler =
|
||||
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ impl AsyncWatcher {
|
|||
uvll::uv_async_init(loop_.handle, handle, async_cb)
|
||||
}, 0);
|
||||
let flag = Exclusive::new(false);
|
||||
let payload = ~Payload { callback: cb, exit_flag: flag.clone() };
|
||||
let payload = box Payload { callback: cb, exit_flag: flag.clone() };
|
||||
unsafe {
|
||||
let payload: *u8 = cast::transmute(payload);
|
||||
uvll::set_data_for_uv_handle(handle, payload);
|
||||
|
@ -146,7 +146,7 @@ mod test_remote {
|
|||
}
|
||||
|
||||
let (tx, rx) = channel();
|
||||
let cb = ~MyCallback(Some(tx));
|
||||
let cb = box MyCallback(Some(tx));
|
||||
let watcher = AsyncWatcher::new(&mut local_loop().loop_, cb);
|
||||
|
||||
let thread = Thread::start(proc() {
|
||||
|
|
|
@ -28,7 +28,7 @@ impl IdleWatcher {
|
|||
assert_eq!(unsafe {
|
||||
uvll::uv_idle_init(loop_.handle, handle)
|
||||
}, 0);
|
||||
let me = ~IdleWatcher {
|
||||
let me = box IdleWatcher {
|
||||
handle: handle,
|
||||
idle_flag: false,
|
||||
closed: false,
|
||||
|
@ -41,7 +41,7 @@ impl IdleWatcher {
|
|||
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
|
||||
unsafe {
|
||||
assert_eq!(uvll::uv_idle_init(loop_.handle, handle), 0);
|
||||
let data: *c_void = cast::transmute(~f);
|
||||
let data: *c_void = cast::transmute(box f);
|
||||
uvll::set_data_for_uv_handle(handle, data);
|
||||
assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0)
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ mod test {
|
|||
|
||||
fn mk(v: uint) -> (~IdleWatcher, Chan) {
|
||||
let rc = Rc::new(RefCell::new((None, 0)));
|
||||
let cb = ~MyCallback(rc.clone(), v);
|
||||
let cb = box MyCallback(rc.clone(), v);
|
||||
let cb = cb as ~Callback:;
|
||||
let cb = unsafe { cast::transmute(cb) };
|
||||
(IdleWatcher::new(&mut local_loop().loop_, cb), rc)
|
||||
|
@ -173,7 +173,7 @@ mod test {
|
|||
// never reschedule us, so we're guaranteed to stay on the same
|
||||
// task/event loop.
|
||||
use std::io;
|
||||
drop(io::stdio::set_stderr(~io::util::NullWriter));
|
||||
drop(io::stdio::set_stderr(box io::util::NullWriter));
|
||||
|
||||
let (mut idle, _chan) = mk(1);
|
||||
idle.resume();
|
||||
|
|
|
@ -125,7 +125,7 @@ pub mod stream;
|
|||
/// }
|
||||
/// ```
|
||||
pub fn event_loop() -> ~rtio::EventLoop:Send {
|
||||
~uvio::UvEventLoop::new() as ~rtio::EventLoop:Send
|
||||
box uvio::UvEventLoop::new() as ~rtio::EventLoop:Send
|
||||
}
|
||||
|
||||
/// A type that wraps a uv handle
|
||||
|
|
|
@ -456,7 +456,7 @@ impl rtio::RtioTcpStream for TcpWatcher {
|
|||
}
|
||||
|
||||
fn clone(&self) -> ~rtio::RtioTcpStream:Send {
|
||||
~TcpWatcher {
|
||||
box TcpWatcher {
|
||||
handle: self.handle,
|
||||
stream: StreamWatcher::new(self.handle),
|
||||
home: self.home.clone(),
|
||||
|
@ -522,7 +522,7 @@ impl TcpListener {
|
|||
uvll::uv_tcp_init(io.uv_loop(), handle)
|
||||
}, 0);
|
||||
let (tx, rx) = channel();
|
||||
let l = ~TcpListener {
|
||||
let l = box TcpListener {
|
||||
home: io.make_handle(),
|
||||
handle: handle,
|
||||
closing_task: None,
|
||||
|
@ -559,7 +559,7 @@ impl rtio::RtioSocket for TcpListener {
|
|||
impl rtio::RtioTcpListener for TcpListener {
|
||||
fn listen(~self) -> Result<~rtio::RtioTcpAcceptor:Send, IoError> {
|
||||
// create the acceptor object from ourselves
|
||||
let mut acceptor = ~TcpAcceptor {
|
||||
let mut acceptor = box TcpAcceptor {
|
||||
listener: self,
|
||||
timeout: AcceptTimeout::new(),
|
||||
};
|
||||
|
@ -583,7 +583,7 @@ extern fn listen_cb(server: *uvll::uv_stream_t, status: c_int) {
|
|||
});
|
||||
let client = TcpWatcher::new_home(&loop_, tcp.home().clone());
|
||||
assert_eq!(unsafe { uvll::uv_accept(server, client.handle) }, 0);
|
||||
Ok(~client as ~rtio::RtioTcpStream:Send)
|
||||
Ok(box client as ~rtio::RtioTcpStream:Send)
|
||||
}
|
||||
n => Err(uv_error_to_io_error(UvError(n)))
|
||||
};
|
||||
|
@ -880,7 +880,7 @@ impl rtio::RtioUdpSocket for UdpWatcher {
|
|||
}
|
||||
|
||||
fn clone(&self) -> ~rtio::RtioUdpSocket:Send {
|
||||
~UdpWatcher {
|
||||
box UdpWatcher {
|
||||
handle: self.handle,
|
||||
home: self.home.clone(),
|
||||
refcount: self.refcount.clone(),
|
||||
|
|
|
@ -122,7 +122,7 @@ impl RtioPipe for PipeWatcher {
|
|||
}
|
||||
|
||||
fn clone(&self) -> ~RtioPipe:Send {
|
||||
~PipeWatcher {
|
||||
box PipeWatcher {
|
||||
stream: StreamWatcher::new(self.stream.handle),
|
||||
defused: false,
|
||||
home: self.home.clone(),
|
||||
|
@ -165,7 +165,7 @@ impl PipeListener {
|
|||
// we close the pipe differently. We can't rely on
|
||||
// StreamWatcher's default close method.
|
||||
let (tx, rx) = channel();
|
||||
let p = ~PipeListener {
|
||||
let p = box PipeListener {
|
||||
home: io.make_handle(),
|
||||
pipe: pipe.unwrap(),
|
||||
incoming: rx,
|
||||
|
@ -181,7 +181,7 @@ impl PipeListener {
|
|||
impl RtioUnixListener for PipeListener {
|
||||
fn listen(~self) -> Result<~RtioUnixAcceptor:Send, IoError> {
|
||||
// create the acceptor object from ourselves
|
||||
let mut acceptor = ~PipeAcceptor {
|
||||
let mut acceptor = box PipeAcceptor {
|
||||
listener: self,
|
||||
timeout: net::AcceptTimeout::new(),
|
||||
};
|
||||
|
@ -214,7 +214,7 @@ extern fn listen_cb(server: *uvll::uv_stream_t, status: libc::c_int) {
|
|||
});
|
||||
let client = PipeWatcher::new_home(&loop_, pipe.home().clone(), false);
|
||||
assert_eq!(unsafe { uvll::uv_accept(server, client.handle()) }, 0);
|
||||
Ok(~client as ~RtioPipe:Send)
|
||||
Ok(box client as ~RtioPipe:Send)
|
||||
}
|
||||
n => Err(uv_error_to_io_error(UvError(n)))
|
||||
};
|
||||
|
|
|
@ -87,7 +87,7 @@ impl Process {
|
|||
};
|
||||
|
||||
let handle = UvHandle::alloc(None::<Process>, uvll::UV_PROCESS);
|
||||
let process = ~Process {
|
||||
let process = box Process {
|
||||
handle: handle,
|
||||
home: io_loop.make_handle(),
|
||||
to_wake: None,
|
||||
|
|
|
@ -114,7 +114,7 @@ impl QueuePool {
|
|||
lock: unsafe {NativeMutex::new()},
|
||||
queue: mpsc::Queue::new(),
|
||||
});
|
||||
let q = ~QueuePool {
|
||||
let q = box QueuePool {
|
||||
refcnt: 0,
|
||||
queue: state,
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct SignalWatcher {
|
|||
impl SignalWatcher {
|
||||
pub fn new(io: &mut UvIoFactory, signum: Signum,
|
||||
channel: Sender<Signum>) -> Result<~SignalWatcher, UvError> {
|
||||
let s = ~SignalWatcher {
|
||||
let s = box SignalWatcher {
|
||||
handle: UvHandle::alloc(None::<SignalWatcher>, uvll::UV_SIGNAL),
|
||||
home: io.make_handle(),
|
||||
channel: channel,
|
||||
|
|
|
@ -34,7 +34,7 @@ pub enum NextAction {
|
|||
impl TimerWatcher {
|
||||
pub fn new(io: &mut UvIoFactory) -> ~TimerWatcher {
|
||||
let handle = io.make_handle();
|
||||
let me = ~TimerWatcher::new_home(&io.loop_, handle);
|
||||
let me = box TimerWatcher::new_home(&io.loop_, handle);
|
||||
me.install()
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ impl EventLoop for UvEventLoop {
|
|||
fn remote_callback(&mut self, f: ~rtio::Callback:Send)
|
||||
-> ~rtio::RemoteCallback:Send
|
||||
{
|
||||
~AsyncWatcher::new(&mut self.uvio.loop_, f) as ~rtio::RemoteCallback:Send
|
||||
box AsyncWatcher::new(&mut self.uvio.loop_, f) as ~rtio::RemoteCallback:Send
|
||||
}
|
||||
|
||||
fn io<'a>(&'a mut self) -> Option<&'a mut rtio::IoFactory> {
|
||||
|
@ -154,7 +154,7 @@ impl IoFactory for UvIoFactory {
|
|||
-> Result<~rtio::RtioTcpStream:Send, IoError>
|
||||
{
|
||||
match TcpWatcher::connect(self, addr, timeout) {
|
||||
Ok(t) => Ok(~t as ~rtio::RtioTcpStream:Send),
|
||||
Ok(t) => Ok(box t as ~rtio::RtioTcpStream:Send),
|
||||
Err(e) => Err(uv_error_to_io_error(e)),
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ impl IoFactory for UvIoFactory {
|
|||
|
||||
fn udp_bind(&mut self, addr: SocketAddr) -> Result<~rtio::RtioUdpSocket:Send, IoError> {
|
||||
match UdpWatcher::bind(self, addr) {
|
||||
Ok(u) => Ok(~u as ~rtio::RtioUdpSocket:Send),
|
||||
Ok(u) => Ok(box u as ~rtio::RtioUdpSocket:Send),
|
||||
Err(e) => Err(uv_error_to_io_error(e)),
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ impl IoFactory for UvIoFactory {
|
|||
|
||||
fn fs_from_raw_fd(&mut self, fd: c_int,
|
||||
close: rtio::CloseBehavior) -> ~rtio::RtioFileStream:Send {
|
||||
~FileWatcher::new(self, fd, close) as ~rtio::RtioFileStream:Send
|
||||
box FileWatcher::new(self, fd, close) as ~rtio::RtioFileStream:Send
|
||||
}
|
||||
|
||||
fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess)
|
||||
|
@ -205,7 +205,7 @@ impl IoFactory for UvIoFactory {
|
|||
};
|
||||
|
||||
match FsRequest::open(self, path, flags as int, mode as int) {
|
||||
Ok(fs) => Ok(~fs as ~rtio::RtioFileStream:Send),
|
||||
Ok(fs) => Ok(box fs as ~rtio::RtioFileStream:Send),
|
||||
Err(e) => Err(uv_error_to_io_error(e))
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ impl IoFactory for UvIoFactory {
|
|||
match Process::spawn(self, config) {
|
||||
Ok((p, io)) => {
|
||||
Ok((p as ~rtio::RtioProcess:Send,
|
||||
io.move_iter().map(|i| i.map(|p| ~p as ~rtio::RtioPipe:Send)).collect()))
|
||||
io.move_iter().map(|i| i.map(|p| box p as ~rtio::RtioPipe:Send)).collect()))
|
||||
}
|
||||
Err(e) => Err(uv_error_to_io_error(e)),
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ impl IoFactory for UvIoFactory {
|
|||
fn unix_connect(&mut self, path: &CString,
|
||||
timeout: Option<u64>) -> Result<~rtio::RtioPipe:Send, IoError> {
|
||||
match PipeWatcher::connect(self, path, timeout) {
|
||||
Ok(p) => Ok(~p as ~rtio::RtioPipe:Send),
|
||||
Ok(p) => Ok(box p as ~rtio::RtioPipe:Send),
|
||||
Err(e) => Err(uv_error_to_io_error(e)),
|
||||
}
|
||||
}
|
||||
|
@ -304,14 +304,14 @@ impl IoFactory for UvIoFactory {
|
|||
fn tty_open(&mut self, fd: c_int, readable: bool)
|
||||
-> Result<~rtio::RtioTTY:Send, IoError> {
|
||||
match TtyWatcher::new(self, fd, readable) {
|
||||
Ok(tty) => Ok(~tty as ~rtio::RtioTTY:Send),
|
||||
Ok(tty) => Ok(box tty as ~rtio::RtioTTY:Send),
|
||||
Err(e) => Err(uv_error_to_io_error(e))
|
||||
}
|
||||
}
|
||||
|
||||
fn pipe_open(&mut self, fd: c_int) -> Result<~rtio::RtioPipe:Send, IoError> {
|
||||
match PipeWatcher::open(self, fd) {
|
||||
Ok(s) => Ok(~s as ~rtio::RtioPipe:Send),
|
||||
Ok(s) => Ok(box s as ~rtio::RtioPipe:Send),
|
||||
Err(e) => Err(uv_error_to_io_error(e))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1772,7 +1772,7 @@ impl<T: Iterator<char>> Builder<T> {
|
|||
fn build_object(&mut self) -> Result<Json, BuilderError> {
|
||||
self.bump();
|
||||
|
||||
let mut values = ~TreeMap::new();
|
||||
let mut values = box TreeMap::new();
|
||||
|
||||
while self.token != None {
|
||||
match self.token {
|
||||
|
@ -2213,7 +2213,7 @@ impl<A:ToJson,B:ToJson> ToJson for (A, B) {
|
|||
fn to_json(&self) -> Json {
|
||||
match *self {
|
||||
(ref a, ref b) => {
|
||||
List(~[a.to_json(), b.to_json()])
|
||||
List(box [a.to_json(), b.to_json()])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2223,7 +2223,7 @@ impl<A:ToJson,B:ToJson,C:ToJson> ToJson for (A, B, C) {
|
|||
fn to_json(&self) -> Json {
|
||||
match *self {
|
||||
(ref a, ref b, ref c) => {
|
||||
List(~[a.to_json(), b.to_json(), c.to_json()])
|
||||
List(box [a.to_json(), b.to_json(), c.to_json()])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2239,7 +2239,7 @@ impl<A:ToJson> ToJson for TreeMap<~str, A> {
|
|||
for (key, value) in self.iter() {
|
||||
d.insert((*key).clone(), value.to_json());
|
||||
}
|
||||
Object(~d)
|
||||
Object(box d)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2249,7 +2249,7 @@ impl<A:ToJson> ToJson for HashMap<~str, A> {
|
|||
for (key, value) in self.iter() {
|
||||
d.insert((*key).clone(), value.to_json());
|
||||
}
|
||||
Object(~d)
|
||||
Object(box d)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2305,7 +2305,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn mk_object(items: &[(~str, Json)]) -> Json {
|
||||
let mut d = ~TreeMap::new();
|
||||
let mut d = box TreeMap::new();
|
||||
|
||||
for item in items.iter() {
|
||||
match *item {
|
||||
|
@ -2370,10 +2370,10 @@ mod tests {
|
|||
]".to_owned()
|
||||
);
|
||||
|
||||
let long_test_list = List(~[
|
||||
let long_test_list = List(box [
|
||||
Boolean(false),
|
||||
Null,
|
||||
List(~[String("foo\nbar".to_owned()), Number(3.5)])]);
|
||||
List(box [String("foo\nbar".to_owned()), Number(3.5)])]);
|
||||
|
||||
assert_eq!(long_test_list.to_str(),
|
||||
"[false,null,[\"foo\\nbar\",3.5]]".to_owned());
|
||||
|
@ -2409,7 +2409,7 @@ mod tests {
|
|||
);
|
||||
|
||||
let complex_obj = mk_object([
|
||||
("b".to_owned(), List(~[
|
||||
("b".to_owned(), List(box [
|
||||
mk_object([("c".to_owned(), String("\x0c\r".to_owned()))]),
|
||||
mk_object([("d".to_owned(), String("".to_owned()))])
|
||||
]))
|
||||
|
@ -2441,7 +2441,7 @@ mod tests {
|
|||
|
||||
let a = mk_object([
|
||||
("a".to_owned(), Boolean(true)),
|
||||
("b".to_owned(), List(~[
|
||||
("b".to_owned(), List(box [
|
||||
mk_object([("c".to_owned(), String("\x0c\r".to_owned()))]),
|
||||
mk_object([("d".to_owned(), String("".to_owned()))])
|
||||
]))
|
||||
|
@ -3111,34 +3111,34 @@ mod tests {
|
|||
|
||||
assert_stream_equal(
|
||||
"{}",
|
||||
~[(ObjectStart, ~[]), (ObjectEnd, ~[])]
|
||||
box [(ObjectStart, box []), (ObjectEnd, box [])]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"{\"a\": 3}",
|
||||
~[
|
||||
(ObjectStart, ~[]),
|
||||
(NumberValue(3.0), ~[Key("a")]),
|
||||
(ObjectEnd, ~[]),
|
||||
box [
|
||||
(ObjectStart, box []),
|
||||
(NumberValue(3.0), box [Key("a")]),
|
||||
(ObjectEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"{ \"a\": null, \"b\" : true }",
|
||||
~[
|
||||
(ObjectStart, ~[]),
|
||||
(NullValue, ~[Key("a")]),
|
||||
(BooleanValue(true), ~[Key("b")]),
|
||||
(ObjectEnd, ~[]),
|
||||
box [
|
||||
(ObjectStart, box []),
|
||||
(NullValue, box [Key("a")]),
|
||||
(BooleanValue(true), box [Key("b")]),
|
||||
(ObjectEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"{\"a\" : 1.0 ,\"b\": [ true ]}",
|
||||
~[
|
||||
(ObjectStart, ~[]),
|
||||
(NumberValue(1.0), ~[Key("a")]),
|
||||
(ListStart, ~[Key("b")]),
|
||||
(BooleanValue(true),~[Key("b"), Index(0)]),
|
||||
(ListEnd, ~[Key("b")]),
|
||||
(ObjectEnd, ~[]),
|
||||
box [
|
||||
(ObjectStart, box []),
|
||||
(NumberValue(1.0), box [Key("a")]),
|
||||
(ListStart, box [Key("b")]),
|
||||
(BooleanValue(true),box [Key("b"), Index(0)]),
|
||||
(ListEnd, box [Key("b")]),
|
||||
(ObjectEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
|
@ -3170,70 +3170,70 @@ mod tests {
|
|||
fn test_read_list_streaming() {
|
||||
assert_stream_equal(
|
||||
"[]",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"[ ]",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"[true]",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(BooleanValue(true), ~[Index(0)]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(BooleanValue(true), box [Index(0)]),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"[ false ]",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(BooleanValue(false), ~[Index(0)]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(BooleanValue(false), box [Index(0)]),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"[null]",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(NullValue, ~[Index(0)]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(NullValue, box [Index(0)]),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"[3, 1]",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(NumberValue(3.0), ~[Index(0)]),
|
||||
(NumberValue(1.0), ~[Index(1)]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(NumberValue(3.0), box [Index(0)]),
|
||||
(NumberValue(1.0), box [Index(1)]),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"\n[3, 2]\n",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(NumberValue(3.0), ~[Index(0)]),
|
||||
(NumberValue(2.0), ~[Index(1)]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(NumberValue(3.0), box [Index(0)]),
|
||||
(NumberValue(2.0), box [Index(1)]),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
assert_stream_equal(
|
||||
"[2, [4, 1]]",
|
||||
~[
|
||||
(ListStart, ~[]),
|
||||
(NumberValue(2.0), ~[Index(0)]),
|
||||
(ListStart, ~[Index(1)]),
|
||||
(NumberValue(4.0), ~[Index(1), Index(0)]),
|
||||
(NumberValue(1.0), ~[Index(1), Index(1)]),
|
||||
(ListEnd, ~[Index(1)]),
|
||||
(ListEnd, ~[]),
|
||||
box [
|
||||
(ListStart, box []),
|
||||
(NumberValue(2.0), box [Index(0)]),
|
||||
(ListStart, box [Index(1)]),
|
||||
(NumberValue(4.0), box [Index(1), Index(0)]),
|
||||
(NumberValue(1.0), box [Index(1), Index(1)]),
|
||||
(ListEnd, box [Index(1)]),
|
||||
(ListEnd, box []),
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -399,7 +399,7 @@ impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for ~T {
|
|||
|
||||
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for ~T {
|
||||
fn decode(d: &mut D) -> Result<~T, E> {
|
||||
Ok(~try!(Decodable::decode(d)))
|
||||
Ok(box try!(Decodable::decode(d)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn any_owning() {
|
||||
let (a, b, c) = (~5u as ~Any, ~TEST as ~Any, ~Test as ~Any);
|
||||
let (a, b, c) = (box 5u as ~Any, box TEST as ~Any, box Test as ~Any);
|
||||
|
||||
assert!(a.is::<uint>());
|
||||
assert!(!b.is::<uint>());
|
||||
|
@ -223,7 +223,7 @@ mod tests {
|
|||
#[test]
|
||||
fn any_as_mut() {
|
||||
let mut a = 5u;
|
||||
let mut b = ~7u;
|
||||
let mut b = box 7u;
|
||||
|
||||
let a_r = &mut a as &mut Any;
|
||||
let tmp: &mut uint = b;
|
||||
|
@ -268,20 +268,20 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn any_move() {
|
||||
let a = ~8u as ~Any;
|
||||
let b = ~Test as ~Any;
|
||||
let a = box 8u as ~Any;
|
||||
let b = box Test as ~Any;
|
||||
|
||||
match a.move::<uint>() {
|
||||
Ok(a) => { assert_eq!(a, ~8u); }
|
||||
Ok(a) => { assert_eq!(a, box 8u); }
|
||||
Err(..) => fail!()
|
||||
}
|
||||
match b.move::<Test>() {
|
||||
Ok(a) => { assert_eq!(a, ~Test); }
|
||||
Ok(a) => { assert_eq!(a, box Test); }
|
||||
Err(..) => fail!()
|
||||
}
|
||||
|
||||
let a = ~8u as ~Any;
|
||||
let b = ~Test as ~Any;
|
||||
let a = box 8u as ~Any;
|
||||
let b = box Test as ~Any;
|
||||
|
||||
assert!(a.move::<~Test>().is_err());
|
||||
assert!(b.move::<~uint>().is_err());
|
||||
|
@ -289,8 +289,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
let a = ~8u as ~Any;
|
||||
let b = ~Test as ~Any;
|
||||
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());
|
||||
|
||||
|
|
|
@ -492,7 +492,7 @@ mod tests {
|
|||
macro_rules! v2ascii (
|
||||
( [$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
|
||||
(&[$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
|
||||
(~[$($e:expr),*]) => (~[$(Ascii{chr:$e}),*]);
|
||||
(~[$($e:expr),*]) => (box [$(Ascii{chr:$e}),*]);
|
||||
)
|
||||
|
||||
macro_rules! vec2ascii (
|
||||
|
@ -536,7 +536,7 @@ mod tests {
|
|||
assert_eq!("( ;".to_ascii(), v2ascii!([40, 32, 59]));
|
||||
// FIXME: #5475 borrowchk error, owned vectors do not live long enough
|
||||
// if chained-from directly
|
||||
let v = ~[40u8, 32u8, 59u8]; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
|
||||
let v = box [40u8, 32u8, 59u8]; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
|
||||
let v = "( ;".to_owned(); assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
|
||||
|
||||
assert_eq!("abCDef&?#".to_ascii().to_lower().into_str(), "abcdef&?#".to_owned());
|
||||
|
@ -569,7 +569,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_owned_ascii_vec() {
|
||||
assert_eq!(("( ;".to_owned()).into_ascii(), v2ascii!(~[40, 32, 59]));
|
||||
assert_eq!((~[40u8, 32u8, 59u8]).into_ascii(), v2ascii!(~[40, 32, 59]));
|
||||
assert_eq!((box [40u8, 32u8, 59u8]).into_ascii(), v2ascii!(~[40, 32, 59]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -586,7 +586,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_ascii_to_bytes() {
|
||||
assert_eq!(v2ascii!(~[40, 32, 59]).into_bytes(), ~[40u8, 32u8, 59u8]);
|
||||
assert_eq!(v2ascii!(~[40, 32, 59]).into_bytes(), box [40u8, 32u8, 59u8]);
|
||||
}
|
||||
|
||||
#[test] #[should_fail]
|
||||
|
@ -625,8 +625,8 @@ mod tests {
|
|||
assert_eq!(v.to_ascii_opt(), Some(v2));
|
||||
assert_eq!("zoä华".to_ascii_opt(), None);
|
||||
|
||||
assert_eq!((~[40u8, 32u8, 59u8]).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
|
||||
assert_eq!((~[127u8, 128u8, 255u8]).into_ascii_opt(), None);
|
||||
assert_eq!((box [40u8, 32u8, 59u8]).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
|
||||
assert_eq!((box [127u8, 128u8, 255u8]).into_ascii_opt(), None);
|
||||
|
||||
assert_eq!(("( ;".to_owned()).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
|
||||
assert_eq!(("zoä华".to_owned()).into_ascii_opt(), None);
|
||||
|
|
|
@ -142,7 +142,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_transmute2() {
|
||||
unsafe {
|
||||
assert_eq!(~[76u8], transmute("L".to_owned()));
|
||||
assert_eq!(box [76u8], transmute("L".to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ pub trait Clone {
|
|||
impl<T: Clone> Clone for ~T {
|
||||
/// Return a copy of the owned box.
|
||||
#[inline]
|
||||
fn clone(&self) -> ~T { ~(**self).clone() }
|
||||
fn clone(&self) -> ~T { box {(**self).clone()} }
|
||||
|
||||
/// Perform copy-assignment from `source` by reusing the existing allocation.
|
||||
#[inline]
|
||||
|
@ -126,7 +126,7 @@ extern_fn_clone!(A, B, C, D, E, F, G, H)
|
|||
|
||||
#[test]
|
||||
fn test_owned_clone() {
|
||||
let a = ~5i;
|
||||
let a = box 5i;
|
||||
let b: ~int = a.clone();
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
@ -148,8 +148,8 @@ fn test_borrowed_clone() {
|
|||
|
||||
#[test]
|
||||
fn test_clone_from() {
|
||||
let a = ~5;
|
||||
let mut b = ~10;
|
||||
let a = box 5;
|
||||
let mut b = box 10;
|
||||
b.clone_from(&a);
|
||||
assert_eq!(*b, 5);
|
||||
}
|
||||
|
|
|
@ -976,14 +976,14 @@ mod test {
|
|||
|
||||
test!(fn drop_full() {
|
||||
let (tx, _rx) = channel();
|
||||
tx.send(~1);
|
||||
tx.send(box 1);
|
||||
})
|
||||
|
||||
test!(fn drop_full_shared() {
|
||||
let (tx, _rx) = channel();
|
||||
drop(tx.clone());
|
||||
drop(tx.clone());
|
||||
tx.send(~1);
|
||||
tx.send(box 1);
|
||||
})
|
||||
|
||||
test!(fn smoke_shared() {
|
||||
|
@ -1179,7 +1179,7 @@ mod test {
|
|||
// Testing that the sender cleans up the payload if receiver is closed
|
||||
let (tx, rx) = channel::<~int>();
|
||||
drop(rx);
|
||||
tx.send(~0);
|
||||
tx.send(box 0);
|
||||
} #[should_fail])
|
||||
|
||||
test!(fn oneshot_single_thread_recv_chan_close() {
|
||||
|
@ -1195,8 +1195,8 @@ mod test {
|
|||
|
||||
test!(fn oneshot_single_thread_send_then_recv() {
|
||||
let (tx, rx) = channel::<~int>();
|
||||
tx.send(~10);
|
||||
assert!(rx.recv() == ~10);
|
||||
tx.send(box 10);
|
||||
assert!(rx.recv() == box 10);
|
||||
})
|
||||
|
||||
test!(fn oneshot_single_thread_try_send_open() {
|
||||
|
@ -1245,10 +1245,10 @@ mod test {
|
|||
test!(fn oneshot_multi_task_recv_then_send() {
|
||||
let (tx, rx) = channel::<~int>();
|
||||
spawn(proc() {
|
||||
assert!(rx.recv() == ~10);
|
||||
assert!(rx.recv() == box 10);
|
||||
});
|
||||
|
||||
tx.send(~10);
|
||||
tx.send(box 10);
|
||||
})
|
||||
|
||||
test!(fn oneshot_multi_task_recv_then_close() {
|
||||
|
@ -1257,7 +1257,7 @@ mod test {
|
|||
drop(tx);
|
||||
});
|
||||
let res = task::try(proc() {
|
||||
assert!(rx.recv() == ~10);
|
||||
assert!(rx.recv() == box 10);
|
||||
});
|
||||
assert!(res.is_err());
|
||||
})
|
||||
|
@ -1305,10 +1305,10 @@ mod test {
|
|||
for _ in range(0, stress_factor()) {
|
||||
let (tx, rx) = channel();
|
||||
spawn(proc() {
|
||||
tx.send(~10);
|
||||
tx.send(box 10);
|
||||
});
|
||||
spawn(proc() {
|
||||
assert!(rx.recv() == ~10);
|
||||
assert!(rx.recv() == box 10);
|
||||
});
|
||||
}
|
||||
})
|
||||
|
@ -1324,7 +1324,7 @@ mod test {
|
|||
if i == 10 { return }
|
||||
|
||||
spawn(proc() {
|
||||
tx.send(~i);
|
||||
tx.send(box i);
|
||||
send(tx, i + 1);
|
||||
});
|
||||
}
|
||||
|
@ -1333,7 +1333,7 @@ mod test {
|
|||
if i == 10 { return }
|
||||
|
||||
spawn(proc() {
|
||||
assert!(rx.recv() == ~i);
|
||||
assert!(rx.recv() == box i);
|
||||
recv(rx, i + 1);
|
||||
});
|
||||
}
|
||||
|
@ -1509,7 +1509,7 @@ mod sync_tests {
|
|||
|
||||
test!(fn drop_full() {
|
||||
let (tx, _rx) = sync_channel(1);
|
||||
tx.send(~1);
|
||||
tx.send(box 1);
|
||||
})
|
||||
|
||||
test!(fn smoke_shared() {
|
||||
|
@ -1639,7 +1639,7 @@ mod sync_tests {
|
|||
// Testing that the sender cleans up the payload if receiver is closed
|
||||
let (tx, rx) = sync_channel::<~int>(0);
|
||||
drop(rx);
|
||||
tx.send(~0);
|
||||
tx.send(box 0);
|
||||
} #[should_fail])
|
||||
|
||||
test!(fn oneshot_single_thread_recv_chan_close() {
|
||||
|
@ -1655,8 +1655,8 @@ mod sync_tests {
|
|||
|
||||
test!(fn oneshot_single_thread_send_then_recv() {
|
||||
let (tx, rx) = sync_channel::<~int>(1);
|
||||
tx.send(~10);
|
||||
assert!(rx.recv() == ~10);
|
||||
tx.send(box 10);
|
||||
assert!(rx.recv() == box 10);
|
||||
})
|
||||
|
||||
test!(fn oneshot_single_thread_try_send_open() {
|
||||
|
@ -1710,10 +1710,10 @@ mod sync_tests {
|
|||
test!(fn oneshot_multi_task_recv_then_send() {
|
||||
let (tx, rx) = sync_channel::<~int>(0);
|
||||
spawn(proc() {
|
||||
assert!(rx.recv() == ~10);
|
||||
assert!(rx.recv() == box 10);
|
||||
});
|
||||
|
||||
tx.send(~10);
|
||||
tx.send(box 10);
|
||||
})
|
||||
|
||||
test!(fn oneshot_multi_task_recv_then_close() {
|
||||
|
@ -1722,7 +1722,7 @@ mod sync_tests {
|
|||
drop(tx);
|
||||
});
|
||||
let res = task::try(proc() {
|
||||
assert!(rx.recv() == ~10);
|
||||
assert!(rx.recv() == box 10);
|
||||
});
|
||||
assert!(res.is_err());
|
||||
})
|
||||
|
@ -1770,10 +1770,10 @@ mod sync_tests {
|
|||
for _ in range(0, stress_factor()) {
|
||||
let (tx, rx) = sync_channel(0);
|
||||
spawn(proc() {
|
||||
tx.send(~10);
|
||||
tx.send(box 10);
|
||||
});
|
||||
spawn(proc() {
|
||||
assert!(rx.recv() == ~10);
|
||||
assert!(rx.recv() == box 10);
|
||||
});
|
||||
}
|
||||
})
|
||||
|
@ -1789,7 +1789,7 @@ mod sync_tests {
|
|||
if i == 10 { return }
|
||||
|
||||
spawn(proc() {
|
||||
tx.send(~i);
|
||||
tx.send(box i);
|
||||
send(tx, i + 1);
|
||||
});
|
||||
}
|
||||
|
@ -1798,7 +1798,7 @@ mod sync_tests {
|
|||
if i == 10 { return }
|
||||
|
||||
spawn(proc() {
|
||||
assert!(rx.recv() == ~i);
|
||||
assert!(rx.recv() == box i);
|
||||
recv(rx, i + 1);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -21,5 +21,5 @@ impl<T: Default + 'static> Default for @T {
|
|||
}
|
||||
|
||||
impl<T: Default> Default for ~T {
|
||||
fn default() -> ~T { ~Default::default() }
|
||||
fn default() -> ~T { box Default::default() }
|
||||
}
|
||||
|
|
|
@ -499,7 +499,7 @@ impl<'a> Parser<'a> {
|
|||
vec!()
|
||||
}
|
||||
};
|
||||
~Select(arms, other)
|
||||
box Select(arms, other)
|
||||
}
|
||||
|
||||
/// Parses a 'plural' statement (after the initial 'plural' word)
|
||||
|
@ -597,7 +597,7 @@ impl<'a> Parser<'a> {
|
|||
vec!()
|
||||
}
|
||||
};
|
||||
~Plural(offset, arms, other)
|
||||
box Plural(offset, arms, other)
|
||||
}
|
||||
|
||||
/// Parses a Count parameter at the current position. This does not check
|
||||
|
@ -912,25 +912,25 @@ mod tests {
|
|||
same("{, select, other { haha } }", [Argument(Argument{
|
||||
position: ArgumentNext,
|
||||
format: fmtdflt(),
|
||||
method: Some(~Select(vec![], vec![String(" haha ")]))
|
||||
method: Some(box Select(vec![], vec![String(" haha ")]))
|
||||
})]);
|
||||
same("{1, select, other { haha } }", [Argument(Argument{
|
||||
position: ArgumentIs(1),
|
||||
format: fmtdflt(),
|
||||
method: Some(~Select(vec![], vec![String(" haha ")]))
|
||||
method: Some(box Select(vec![], vec![String(" haha ")]))
|
||||
})]);
|
||||
same("{1, select, other {#} }", [Argument(Argument{
|
||||
position: ArgumentIs(1),
|
||||
format: fmtdflt(),
|
||||
method: Some(~Select(vec![], vec![CurrentArgument]))
|
||||
method: Some(box Select(vec![], vec![CurrentArgument]))
|
||||
})]);
|
||||
same("{1, select, other {{2, select, other {lol}}} }", [Argument(Argument{
|
||||
position: ArgumentIs(1),
|
||||
format: fmtdflt(),
|
||||
method: Some(~Select(vec![], vec![Argument(Argument{
|
||||
method: Some(box Select(vec![], vec![Argument(Argument{
|
||||
position: ArgumentIs(2),
|
||||
format: fmtdflt(),
|
||||
method: Some(~Select(vec![], vec![String("lol")]))
|
||||
method: Some(box Select(vec![], vec![String("lol")]))
|
||||
})])) // wat
|
||||
})]);
|
||||
}
|
||||
|
@ -940,7 +940,7 @@ mod tests {
|
|||
same("{1, select, a{1} b{2} c{3} other{4} }", [Argument(Argument{
|
||||
position: ArgumentIs(1),
|
||||
format: fmtdflt(),
|
||||
method: Some(~Select(vec![
|
||||
method: Some(box Select(vec![
|
||||
SelectArm{ selector: "a", result: vec![String("1")] },
|
||||
SelectArm{ selector: "b", result: vec![String("2")] },
|
||||
SelectArm{ selector: "c", result: vec![String("3")] },
|
||||
|
@ -964,18 +964,18 @@ mod tests {
|
|||
same("{, plural, other { haha } }", [Argument(Argument{
|
||||
position: ArgumentNext,
|
||||
format: fmtdflt(),
|
||||
method: Some(~Plural(None, vec![], vec![String(" haha ")]))
|
||||
method: Some(box Plural(None, vec![], vec![String(" haha ")]))
|
||||
})]);
|
||||
same("{:, plural, other { haha } }", [Argument(Argument{
|
||||
position: ArgumentNext,
|
||||
format: fmtdflt(),
|
||||
method: Some(~Plural(None, vec![], vec![String(" haha ")]))
|
||||
method: Some(box Plural(None, vec![], vec![String(" haha ")]))
|
||||
})]);
|
||||
same("{, plural, offset:1 =2{2} =3{3} many{yes} other{haha} }",
|
||||
[Argument(Argument{
|
||||
position: ArgumentNext,
|
||||
format: fmtdflt(),
|
||||
method: Some(~Plural(Some(1), vec![
|
||||
method: Some(box Plural(Some(1), vec![
|
||||
PluralArm{ selector: Literal(2), result: vec![String("2")] },
|
||||
PluralArm{ selector: Literal(3), result: vec![String("3")] },
|
||||
PluralArm{ selector: Keyword(Many), result: vec![String("yes")] }
|
||||
|
|
|
@ -117,7 +117,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_destructor() {
|
||||
let x = Gc::new(~5);
|
||||
let x = Gc::new(box 5);
|
||||
assert_eq!(**x.borrow(), 5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -467,7 +467,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn result_bytes(h: u64) -> ~[u8] {
|
||||
~[(h >> 0) as u8,
|
||||
box [(h >> 0) as u8,
|
||||
(h >> 8) as u8,
|
||||
(h >> 16) as u8,
|
||||
(h >> 24) as u8,
|
||||
|
|
|
@ -139,40 +139,40 @@ mod test {
|
|||
fn test_rx_reader() {
|
||||
let (tx, rx) = channel();
|
||||
task::spawn(proc() {
|
||||
tx.send(~[1u8, 2u8]);
|
||||
tx.send(~[]);
|
||||
tx.send(~[3u8, 4u8]);
|
||||
tx.send(~[5u8, 6u8]);
|
||||
tx.send(~[7u8, 8u8]);
|
||||
tx.send(box [1u8, 2u8]);
|
||||
tx.send(box []);
|
||||
tx.send(box [3u8, 4u8]);
|
||||
tx.send(box [5u8, 6u8]);
|
||||
tx.send(box [7u8, 8u8]);
|
||||
});
|
||||
|
||||
let mut reader = ChanReader::new(rx);
|
||||
let mut buf = ~[0u8, ..3];
|
||||
let mut buf = box [0u8, ..3];
|
||||
|
||||
|
||||
assert_eq!(Ok(0), reader.read([]));
|
||||
|
||||
assert_eq!(Ok(3), reader.read(buf));
|
||||
assert_eq!(~[1,2,3], buf);
|
||||
assert_eq!(box [1,2,3], buf);
|
||||
|
||||
assert_eq!(Ok(3), reader.read(buf));
|
||||
assert_eq!(~[4,5,6], buf);
|
||||
assert_eq!(box [4,5,6], buf);
|
||||
|
||||
assert_eq!(Ok(2), reader.read(buf));
|
||||
assert_eq!(~[7,8,6], buf);
|
||||
assert_eq!(box [7,8,6], buf);
|
||||
|
||||
match reader.read(buf) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.kind, io::EndOfFile),
|
||||
}
|
||||
assert_eq!(~[7,8,6], buf);
|
||||
assert_eq!(box [7,8,6], buf);
|
||||
|
||||
// Ensure it continues to fail in the same way.
|
||||
match reader.read(buf) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.kind, io::EndOfFile),
|
||||
}
|
||||
assert_eq!(~[7,8,6], buf);
|
||||
assert_eq!(box [7,8,6], buf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -181,7 +181,7 @@ mod test {
|
|||
let mut writer = ChanWriter::new(tx);
|
||||
writer.write_be_u32(42).unwrap();
|
||||
|
||||
let wanted = ~[0u8, 0u8, 0u8, 42u8];
|
||||
let wanted = box [0u8, 0u8, 0u8, 42u8];
|
||||
let got = task::try(proc() { rx.recv() }).unwrap();
|
||||
assert_eq!(wanted, got);
|
||||
|
||||
|
|
|
@ -447,7 +447,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_read_f32() {
|
||||
//big-endian floating-point 8.1250
|
||||
let buf = ~[0x41, 0x02, 0x00, 0x00];
|
||||
let buf = box [0x41, 0x02, 0x00, 0x00];
|
||||
|
||||
let mut writer = MemWriter::new();
|
||||
writer.write(buf).unwrap();
|
||||
|
|
|
@ -450,7 +450,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_buf_reader() {
|
||||
let in_buf = ~[0, 1, 2, 3, 4, 5, 6, 7];
|
||||
let in_buf = box [0, 1, 2, 3, 4, 5, 6, 7];
|
||||
let mut reader = BufReader::new(in_buf);
|
||||
let mut buf = [];
|
||||
assert_eq!(reader.read(buf), Ok(0));
|
||||
|
|
|
@ -243,7 +243,7 @@ mod test {
|
|||
spawn(proc() {
|
||||
match UdpSocket::bind(client_ip) {
|
||||
Ok(client) => {
|
||||
let client = ~client;
|
||||
let client = box client;
|
||||
let mut stream = client.connect(server_ip);
|
||||
rx1.recv();
|
||||
stream.write([99]).unwrap();
|
||||
|
@ -255,7 +255,7 @@ mod test {
|
|||
|
||||
match UdpSocket::bind(server_ip) {
|
||||
Ok(server) => {
|
||||
let server = ~server;
|
||||
let server = box server;
|
||||
let mut stream = server.connect(client_ip);
|
||||
tx1.send(());
|
||||
let mut buf = [0];
|
||||
|
@ -281,7 +281,7 @@ mod test {
|
|||
spawn(proc() {
|
||||
match UdpSocket::bind(client_ip) {
|
||||
Ok(client) => {
|
||||
let client = ~client;
|
||||
let client = box client;
|
||||
let mut stream = client.connect(server_ip);
|
||||
rx1.recv();
|
||||
stream.write([99]).unwrap();
|
||||
|
@ -293,7 +293,7 @@ mod test {
|
|||
|
||||
match UdpSocket::bind(server_ip) {
|
||||
Ok(server) => {
|
||||
let server = ~server;
|
||||
let server = box server;
|
||||
let mut stream = server.connect(client_ip);
|
||||
tx1.send(());
|
||||
let mut buf = [0];
|
||||
|
|
|
@ -417,7 +417,7 @@ impl Drop for Process {
|
|||
drop(self.stdin.take());
|
||||
drop(self.stdout.take());
|
||||
drop(self.stderr.take());
|
||||
drop(mem::replace(&mut self.extra_io, ~[]));
|
||||
drop(mem::replace(&mut self.extra_io, box []));
|
||||
|
||||
self.wait();
|
||||
}
|
||||
|
@ -804,7 +804,7 @@ mod tests {
|
|||
})
|
||||
|
||||
iotest!(fn test_add_to_env() {
|
||||
let new_env = ~[("RUN_TEST_NEW_ENV".to_owned(), "123".to_owned())];
|
||||
let new_env = box [("RUN_TEST_NEW_ENV".to_owned(), "123".to_owned())];
|
||||
|
||||
let mut prog = run_env(Some(new_env));
|
||||
let result = prog.wait_with_output();
|
||||
|
|
|
@ -216,7 +216,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) {
|
|||
Local::put(task);
|
||||
|
||||
if my_stdout.is_none() {
|
||||
my_stdout = Some(~stdout() as ~Writer:Send);
|
||||
my_stdout = Some(box stdout() as ~Writer:Send);
|
||||
}
|
||||
let ret = f(*my_stdout.get_mut_ref());
|
||||
|
||||
|
@ -396,7 +396,7 @@ mod tests {
|
|||
let (tx, rx) = channel();
|
||||
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
|
||||
spawn(proc() {
|
||||
set_stdout(~w);
|
||||
set_stdout(box w);
|
||||
println!("hello!");
|
||||
});
|
||||
assert_eq!(r.read_to_str().unwrap(), "hello!\n".to_owned());
|
||||
|
@ -408,7 +408,7 @@ mod tests {
|
|||
let (tx, rx) = channel();
|
||||
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
|
||||
spawn(proc() {
|
||||
set_stderr(~w);
|
||||
set_stderr(box w);
|
||||
fail!("my special message");
|
||||
});
|
||||
let s = r.read_to_str().unwrap();
|
||||
|
|
|
@ -235,7 +235,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_null_writer() {
|
||||
let mut s = NullWriter;
|
||||
let buf = ~[0, 0, 0];
|
||||
let buf = box [0, 0, 0];
|
||||
s.write(buf).unwrap();
|
||||
s.flush().unwrap();
|
||||
}
|
||||
|
@ -243,15 +243,15 @@ mod test {
|
|||
#[test]
|
||||
fn test_zero_reader() {
|
||||
let mut s = ZeroReader;
|
||||
let mut buf = ~[1, 2, 3];
|
||||
let mut buf = box [1, 2, 3];
|
||||
assert_eq!(s.read(buf), Ok(3));
|
||||
assert_eq!(~[0, 0, 0], buf);
|
||||
assert_eq!(box [0, 0, 0], buf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_null_reader() {
|
||||
let mut r = NullReader;
|
||||
let mut buf = ~[0];
|
||||
let mut buf = box [0];
|
||||
assert!(r.read(buf).is_err());
|
||||
}
|
||||
|
||||
|
@ -273,8 +273,8 @@ mod test {
|
|||
}
|
||||
}
|
||||
|
||||
let mut multi = MultiWriter::new(vec!(~TestWriter as ~Writer,
|
||||
~TestWriter as ~Writer));
|
||||
let mut multi = MultiWriter::new(vec!(box TestWriter as ~Writer,
|
||||
box TestWriter as ~Writer));
|
||||
multi.write([1, 2, 3]).unwrap();
|
||||
assert_eq!(2, unsafe { writes });
|
||||
assert_eq!(0, unsafe { flushes });
|
||||
|
|
|
@ -2340,7 +2340,7 @@ mod tests {
|
|||
fn test_counter_from_iter() {
|
||||
let it = count(0, 5).take(10);
|
||||
let xs: ~[int] = FromIterator::from_iter(it);
|
||||
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
|
||||
assert_eq!(xs, box [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2370,7 +2370,7 @@ mod tests {
|
|||
fn test_filter_map() {
|
||||
let mut it = count(0u, 1u).take(10)
|
||||
.filter_map(|x| if x % 2 == 0 { Some(x*x) } else { None });
|
||||
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
|
||||
assert_eq!(it.collect::<~[uint]>(), box [0*0, 2*2, 4*4, 6*6, 8*8]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2384,7 +2384,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_iterator_peekable() {
|
||||
let xs = ~[0u, 1, 2, 3, 4, 5];
|
||||
let xs = box [0u, 1, 2, 3, 4, 5];
|
||||
let mut it = xs.iter().map(|&x|x).peekable();
|
||||
assert_eq!(it.peek().unwrap(), &0);
|
||||
assert_eq!(it.next().unwrap(), 0);
|
||||
|
@ -2627,14 +2627,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_collect() {
|
||||
let a = ~[1, 2, 3, 4, 5];
|
||||
let a = box [1, 2, 3, 4, 5];
|
||||
let b: ~[int] = a.iter().map(|&x| x).collect();
|
||||
assert_eq!(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_all() {
|
||||
let v: ~&[int] = ~&[1, 2, 3, 4, 5];
|
||||
let v: ~&[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 +2643,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_any() {
|
||||
let v: ~&[int] = ~&[1, 2, 3, 4, 5];
|
||||
let v: ~&[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));
|
||||
|
@ -2701,7 +2701,7 @@ mod tests {
|
|||
let mut it = xs.iter();
|
||||
it.next();
|
||||
it.next();
|
||||
assert_eq!(it.rev().map(|&x| x).collect::<~[int]>(), ~[16, 14, 12, 10, 8, 6]);
|
||||
assert_eq!(it.rev().map(|&x| x).collect::<~[int]>(), box [16, 14, 12, 10, 8, 6]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2767,7 +2767,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_double_ended_chain() {
|
||||
let xs = [1, 2, 3, 4, 5];
|
||||
let ys = ~[7, 9, 11];
|
||||
let ys = box [7, 9, 11];
|
||||
let mut it = xs.iter().chain(ys.iter()).rev();
|
||||
assert_eq!(it.next().unwrap(), &11)
|
||||
assert_eq!(it.next().unwrap(), &9)
|
||||
|
@ -2784,7 +2784,7 @@ mod tests {
|
|||
fn test_rposition() {
|
||||
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
|
||||
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
|
||||
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
let v = box [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
|
||||
|
||||
assert_eq!(v.iter().rposition(f), Some(3u));
|
||||
assert!(v.iter().rposition(g).is_none());
|
||||
|
@ -2793,7 +2793,7 @@ mod tests {
|
|||
#[test]
|
||||
#[should_fail]
|
||||
fn test_rposition_fail() {
|
||||
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
||||
let v = [(box 0, @0), (box 0, @0), (box 0, @0), (box 0, @0)];
|
||||
let mut i = 0;
|
||||
v.iter().rposition(|_elt| {
|
||||
if i == 2 {
|
||||
|
@ -2845,7 +2845,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_random_access_chain() {
|
||||
let xs = [1, 2, 3, 4, 5];
|
||||
let ys = ~[7, 9, 11];
|
||||
let ys = box [7, 9, 11];
|
||||
let mut it = xs.iter().chain(ys.iter());
|
||||
assert_eq!(it.idx(0).unwrap(), &1);
|
||||
assert_eq!(it.idx(5).unwrap(), &7);
|
||||
|
@ -2939,12 +2939,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_double_ended_range() {
|
||||
assert_eq!(range(11i, 14).rev().collect::<~[int]>(), ~[13i, 12, 11]);
|
||||
assert_eq!(range(11i, 14).rev().collect::<~[int]>(), box [13i, 12, 11]);
|
||||
for _ in range(10i, 0).rev() {
|
||||
fail!("unreachable");
|
||||
}
|
||||
|
||||
assert_eq!(range(11u, 14).rev().collect::<~[uint]>(), ~[13u, 12, 11]);
|
||||
assert_eq!(range(11u, 14).rev().collect::<~[uint]>(), box [13u, 12, 11]);
|
||||
for _ in range(10u, 0).rev() {
|
||||
fail!("unreachable");
|
||||
}
|
||||
|
@ -2996,13 +2996,13 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
assert_eq!(range(0i, 5).collect::<~[int]>(), ~[0i, 1, 2, 3, 4]);
|
||||
assert_eq!(range(-10i, -1).collect::<~[int]>(), ~[-10, -9, -8, -7, -6, -5, -4, -3, -2]);
|
||||
assert_eq!(range(0i, 5).rev().collect::<~[int]>(), ~[4, 3, 2, 1, 0]);
|
||||
assert_eq!(range(200, -5).collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range(200, -5).rev().collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range(200, 200).collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range(200, 200).rev().collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range(0i, 5).collect::<~[int]>(), box [0i, 1, 2, 3, 4]);
|
||||
assert_eq!(range(-10i, -1).collect::<~[int]>(), box [-10, -9, -8, -7, -6, -5, -4, -3, -2]);
|
||||
assert_eq!(range(0i, 5).rev().collect::<~[int]>(), box [4, 3, 2, 1, 0]);
|
||||
assert_eq!(range(200, -5).collect::<~[int]>(), box []);
|
||||
assert_eq!(range(200, -5).rev().collect::<~[int]>(), box []);
|
||||
assert_eq!(range(200, 200).collect::<~[int]>(), box []);
|
||||
assert_eq!(range(200, 200).rev().collect::<~[int]>(), box []);
|
||||
|
||||
assert_eq!(range(0i, 100).size_hint(), (100, Some(100)));
|
||||
// this test is only meaningful when sizeof uint < sizeof u64
|
||||
|
@ -3013,32 +3013,32 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_range_inclusive() {
|
||||
assert_eq!(range_inclusive(0i, 5).collect::<~[int]>(), ~[0i, 1, 2, 3, 4, 5]);
|
||||
assert_eq!(range_inclusive(0i, 5).rev().collect::<~[int]>(), ~[5i, 4, 3, 2, 1, 0]);
|
||||
assert_eq!(range_inclusive(200, -5).collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range_inclusive(200, -5).rev().collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range_inclusive(200, 200).collect::<~[int]>(), ~[200]);
|
||||
assert_eq!(range_inclusive(200, 200).rev().collect::<~[int]>(), ~[200]);
|
||||
assert_eq!(range_inclusive(0i, 5).collect::<~[int]>(), box [0i, 1, 2, 3, 4, 5]);
|
||||
assert_eq!(range_inclusive(0i, 5).rev().collect::<~[int]>(), box [5i, 4, 3, 2, 1, 0]);
|
||||
assert_eq!(range_inclusive(200, -5).collect::<~[int]>(), box []);
|
||||
assert_eq!(range_inclusive(200, -5).rev().collect::<~[int]>(), box []);
|
||||
assert_eq!(range_inclusive(200, 200).collect::<~[int]>(), box [200]);
|
||||
assert_eq!(range_inclusive(200, 200).rev().collect::<~[int]>(), box [200]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_step() {
|
||||
assert_eq!(range_step(0i, 20, 5).collect::<~[int]>(), ~[0, 5, 10, 15]);
|
||||
assert_eq!(range_step(20i, 0, -5).collect::<~[int]>(), ~[20, 15, 10, 5]);
|
||||
assert_eq!(range_step(20i, 0, -6).collect::<~[int]>(), ~[20, 14, 8, 2]);
|
||||
assert_eq!(range_step(200u8, 255, 50).collect::<~[u8]>(), ~[200u8, 250]);
|
||||
assert_eq!(range_step(200, -5, 1).collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range_step(200, 200, 1).collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range_step(0i, 20, 5).collect::<~[int]>(), box [0, 5, 10, 15]);
|
||||
assert_eq!(range_step(20i, 0, -5).collect::<~[int]>(), box [20, 15, 10, 5]);
|
||||
assert_eq!(range_step(20i, 0, -6).collect::<~[int]>(), box [20, 14, 8, 2]);
|
||||
assert_eq!(range_step(200u8, 255, 50).collect::<~[u8]>(), box [200u8, 250]);
|
||||
assert_eq!(range_step(200, -5, 1).collect::<~[int]>(), box []);
|
||||
assert_eq!(range_step(200, 200, 1).collect::<~[int]>(), box []);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_step_inclusive() {
|
||||
assert_eq!(range_step_inclusive(0i, 20, 5).collect::<~[int]>(), ~[0, 5, 10, 15, 20]);
|
||||
assert_eq!(range_step_inclusive(20i, 0, -5).collect::<~[int]>(), ~[20, 15, 10, 5, 0]);
|
||||
assert_eq!(range_step_inclusive(20i, 0, -6).collect::<~[int]>(), ~[20, 14, 8, 2]);
|
||||
assert_eq!(range_step_inclusive(200u8, 255, 50).collect::<~[u8]>(), ~[200u8, 250]);
|
||||
assert_eq!(range_step_inclusive(200, -5, 1).collect::<~[int]>(), ~[]);
|
||||
assert_eq!(range_step_inclusive(200, 200, 1).collect::<~[int]>(), ~[200]);
|
||||
assert_eq!(range_step_inclusive(0i, 20, 5).collect::<~[int]>(), box [0, 5, 10, 15, 20]);
|
||||
assert_eq!(range_step_inclusive(20i, 0, -5).collect::<~[int]>(), box [20, 15, 10, 5, 0]);
|
||||
assert_eq!(range_step_inclusive(20i, 0, -6).collect::<~[int]>(), box [20, 14, 8, 2]);
|
||||
assert_eq!(range_step_inclusive(200u8, 255, 50).collect::<~[u8]>(), box [200u8, 250]);
|
||||
assert_eq!(range_step_inclusive(200, -5, 1).collect::<~[int]>(), box []);
|
||||
assert_eq!(range_step_inclusive(200, 200, 1).collect::<~[int]>(), box [200]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -302,7 +302,7 @@ pub fn set<T: 'static>(key: Key<T>, data: T) {
|
|||
// 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 = ~data as ~LocalData:;
|
||||
let data = box data as ~LocalData:;
|
||||
|
||||
fn insertion_position(map: &mut Map,
|
||||
key: *u8) -> Option<uint> {
|
||||
|
@ -486,7 +486,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_owned() {
|
||||
static key: Key<~int> = &Key;
|
||||
set(key, ~1);
|
||||
set(key, box 1);
|
||||
|
||||
get(key, |v| {
|
||||
get(key, |v| {
|
||||
|
@ -497,7 +497,7 @@ mod tests {
|
|||
});
|
||||
assert_eq!(**v.unwrap(), 1);
|
||||
});
|
||||
set(key, ~2);
|
||||
set(key, box 2);
|
||||
get(key, |v| {
|
||||
assert_eq!(**v.unwrap(), 2);
|
||||
})
|
||||
|
|
|
@ -619,7 +619,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_get_ptr() {
|
||||
unsafe {
|
||||
let x = ~0;
|
||||
let x = box 0;
|
||||
let addr_x: *int = ::cast::transmute(&*x);
|
||||
let opt = Some(x);
|
||||
let y = opt.unwrap();
|
||||
|
@ -862,11 +862,11 @@ mod tests {
|
|||
fn test_collect() {
|
||||
let v: Option<~[int]> = collect(range(0, 0)
|
||||
.map(|_| Some(0)));
|
||||
assert_eq!(v, Some(~[]));
|
||||
assert_eq!(v, Some(box []));
|
||||
|
||||
let v: Option<~[int]> = collect(range(0, 3)
|
||||
.map(|x| Some(x)));
|
||||
assert_eq!(v, Some(~[0, 1, 2]));
|
||||
assert_eq!(v, Some(box [0, 1, 2]));
|
||||
|
||||
let v: Option<~[int]> = collect(range(0, 3)
|
||||
.map(|x| if x > 1 { None } else { Some(x) }));
|
||||
|
|
|
@ -225,7 +225,7 @@ pub fn env_as_bytes() -> ~[(~[u8],~[u8])] {
|
|||
for p in input.iter() {
|
||||
let vs: ~[&[u8]] = p.splitn(1, |b| *b == '=' as u8).collect();
|
||||
let key = vs[0].to_owned();
|
||||
let val = if vs.len() < 2 { ~[] } else { vs[1].to_owned() };
|
||||
let val = if vs.len() < 2 { box [] } else { vs[1].to_owned() };
|
||||
pairs.push((key, val));
|
||||
}
|
||||
pairs
|
||||
|
@ -419,7 +419,7 @@ pub fn self_exe_name() -> Option<Path> {
|
|||
unsafe {
|
||||
use libc::funcs::bsd44::*;
|
||||
use libc::consts::os::extra::*;
|
||||
let mib = ~[CTL_KERN as c_int,
|
||||
let mib = box [CTL_KERN as c_int,
|
||||
KERN_PROC as c_int,
|
||||
KERN_PROC_PATHNAME as c_int, -1 as c_int];
|
||||
let mut sz: libc::size_t = 0;
|
||||
|
|
|
@ -544,8 +544,8 @@ pub mod ptr_tests {
|
|||
assert_eq!(p.fst, 50);
|
||||
assert_eq!(p.snd, 60);
|
||||
|
||||
let v0 = ~[32000u16, 32001u16, 32002u16];
|
||||
let mut v1 = ~[0u16, 0u16, 0u16];
|
||||
let v0 = box [32000u16, 32001u16, 32002u16];
|
||||
let mut v1 = box [0u16, 0u16, 0u16];
|
||||
|
||||
copy_memory(v1.as_mut_ptr().offset(1),
|
||||
v0.as_ptr().offset(1), 1);
|
||||
|
@ -579,7 +579,7 @@ pub mod ptr_tests {
|
|||
"hello".with_c_str(|p0| {
|
||||
"there".with_c_str(|p1| {
|
||||
"thing".with_c_str(|p2| {
|
||||
let v = ~[p0, p1, p2, null()];
|
||||
let v = box [p0, p1, p2, null()];
|
||||
unsafe {
|
||||
assert_eq!(buf_len(v.as_ptr()), 3u);
|
||||
}
|
||||
|
@ -627,7 +627,7 @@ pub mod ptr_tests {
|
|||
#[test]
|
||||
fn test_ptr_addition() {
|
||||
unsafe {
|
||||
let xs = ~[5, ..16];
|
||||
let xs = box [5, ..16];
|
||||
let mut ptr = xs.as_ptr();
|
||||
let end = ptr.offset(16);
|
||||
|
||||
|
@ -645,14 +645,14 @@ pub mod ptr_tests {
|
|||
m_ptr = m_ptr.offset(1);
|
||||
}
|
||||
|
||||
assert_eq!(xs_mut, ~[10, ..16]);
|
||||
assert_eq!(xs_mut, box [10, ..16]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ptr_subtraction() {
|
||||
unsafe {
|
||||
let xs = ~[0,1,2,3,4,5,6,7,8,9];
|
||||
let xs = box [0,1,2,3,4,5,6,7,8,9];
|
||||
let mut idx = 9i8;
|
||||
let ptr = xs.as_ptr();
|
||||
|
||||
|
@ -670,7 +670,7 @@ pub mod ptr_tests {
|
|||
m_ptr = m_ptr.offset(-1);
|
||||
}
|
||||
|
||||
assert_eq!(xs_mut, ~[0,2,4,6,8,10,12,14,16,18]);
|
||||
assert_eq!(xs_mut, box [0,2,4,6,8,10,12,14,16,18]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -680,7 +680,7 @@ pub mod ptr_tests {
|
|||
let one = "oneOne".to_c_str();
|
||||
let two = "twoTwo".to_c_str();
|
||||
let three = "threeThree".to_c_str();
|
||||
let arr = ~[
|
||||
let arr = box [
|
||||
one.with_ref(|buf| buf),
|
||||
two.with_ref(|buf| buf),
|
||||
three.with_ref(|buf| buf),
|
||||
|
@ -713,7 +713,7 @@ pub mod ptr_tests {
|
|||
let one = "oneOne".to_c_str();
|
||||
let two = "twoTwo".to_c_str();
|
||||
let three = "threeThree".to_c_str();
|
||||
let arr = ~[
|
||||
let arr = box [
|
||||
one.with_ref(|buf| buf),
|
||||
two.with_ref(|buf| buf),
|
||||
three.with_ref(|buf| buf),
|
||||
|
|
|
@ -58,7 +58,7 @@ impl<T> Rc<T> {
|
|||
// destructor never frees the allocation while the
|
||||
// strong destructor is running, even if the weak
|
||||
// pointer is stored inside the strong one.
|
||||
ptr: transmute(~RcBox {
|
||||
ptr: transmute(box RcBox {
|
||||
value: value,
|
||||
strong: Cell::new(1),
|
||||
weak: Cell::new(1)
|
||||
|
@ -255,7 +255,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_destructor() {
|
||||
let x = Rc::new(~5);
|
||||
let x = Rc::new(box 5);
|
||||
assert_eq!(**x, 5);
|
||||
}
|
||||
|
||||
|
|
|
@ -642,7 +642,7 @@ fn test_repr() {
|
|||
exact_test(&("he\u10f3llo".to_owned()), "~\"he\\u10f3llo\"");
|
||||
|
||||
exact_test(&(@10), "@10");
|
||||
exact_test(&(~10), "~10");
|
||||
exact_test(&(box 10), "~10");
|
||||
exact_test(&(&10), "&10");
|
||||
let mut x = 10;
|
||||
exact_test(&(&mut x), "&mut 10");
|
||||
|
@ -651,7 +651,7 @@ fn test_repr() {
|
|||
exact_test(&(0 as *mut ()), "(0x0 as *mut ())");
|
||||
|
||||
exact_test(&(1,), "(1,)");
|
||||
exact_test(&(~["hi", "there"]),
|
||||
exact_test(&(box ["hi", "there"]),
|
||||
"~[\"hi\", \"there\"]");
|
||||
exact_test(&(&["hi", "there"]),
|
||||
"&[\"hi\", \"there\"]");
|
||||
|
@ -659,7 +659,7 @@ fn test_repr() {
|
|||
"repr::P{a: 10, b: 1.234f64}");
|
||||
exact_test(&(@P{a:10, b:1.234}),
|
||||
"@repr::P{a: 10, b: 1.234f64}");
|
||||
exact_test(&(~P{a:10, b:1.234}),
|
||||
exact_test(&(box P{a:10, b:1.234}),
|
||||
"~repr::P{a: 10, b: 1.234f64}");
|
||||
exact_test(&(10u8, "hello".to_owned()),
|
||||
"(10u8, ~\"hello\")");
|
||||
|
@ -681,10 +681,10 @@ 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(&(~5 as ~ToStr), "~to_str::ToStr<no-bounds>");
|
||||
exact_test(&(box 5 as ~ToStr), "~to_str::ToStr<no-bounds>");
|
||||
|
||||
struct Foo;
|
||||
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::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)");
|
||||
|
|
|
@ -685,10 +685,10 @@ mod tests {
|
|||
#[test]
|
||||
fn test_collect() {
|
||||
let v: Result<~[int], ()> = collect(range(0, 0).map(|_| Ok::<int, ()>(0)));
|
||||
assert_eq!(v, Ok(~[]));
|
||||
assert_eq!(v, Ok(box []));
|
||||
|
||||
let v: Result<~[int], ()> = collect(range(0, 3).map(|x| Ok::<int, ()>(x)));
|
||||
assert_eq!(v, Ok(~[0, 1, 2]));
|
||||
assert_eq!(v, Ok(box [0, 1, 2]));
|
||||
|
||||
let v: Result<~[int], int> = collect(range(0, 3)
|
||||
.map(|x| if x > 1 { Err(x) } else { Ok(x) }));
|
||||
|
|
|
@ -99,7 +99,7 @@ mod imp {
|
|||
with_lock(|| unsafe {
|
||||
let ptr = get_global_ptr();
|
||||
rtassert!((*ptr).is_none());
|
||||
(*ptr) = Some(~args.clone());
|
||||
(*ptr) = Some(box args.clone());
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ mod imp {
|
|||
// Preserve the actual global state.
|
||||
let saved_value = take();
|
||||
|
||||
let expected = ~[bytes!("happy").to_owned(), bytes!("today?").to_owned()];
|
||||
let expected = box [bytes!("happy").to_owned(), bytes!("today?").to_owned()];
|
||||
|
||||
put(expected.clone());
|
||||
assert!(clone() == Some(expected.clone()));
|
||||
|
|
|
@ -36,7 +36,7 @@ pub fn init() {
|
|||
unsafe {
|
||||
rtassert!(!RUNNING);
|
||||
rtassert!(QUEUE.is_null());
|
||||
let state: ~Queue = ~Exclusive::new(vec!());
|
||||
let state: ~Queue = box Exclusive::new(vec!());
|
||||
QUEUE = cast::transmute(state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,14 +125,14 @@ mod bench {
|
|||
#[bench]
|
||||
fn alloc_owned_small(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~10
|
||||
box 10
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn alloc_owned_big(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~[10, ..1000]
|
||||
box [10, ..1000]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ mod test {
|
|||
#[test]
|
||||
fn thread_local_task_smoke_test() {
|
||||
run_in_bare_thread(proc() {
|
||||
let task = ~Task::new();
|
||||
let task = box Task::new();
|
||||
Local::put(task);
|
||||
let task: ~Task = Local::take();
|
||||
cleanup_task(task);
|
||||
|
@ -69,11 +69,11 @@ mod test {
|
|||
#[test]
|
||||
fn thread_local_task_two_instances() {
|
||||
run_in_bare_thread(proc() {
|
||||
let task = ~Task::new();
|
||||
let task = box Task::new();
|
||||
Local::put(task);
|
||||
let task: ~Task = Local::take();
|
||||
cleanup_task(task);
|
||||
let task = ~Task::new();
|
||||
let task = box Task::new();
|
||||
Local::put(task);
|
||||
let task: ~Task = Local::take();
|
||||
cleanup_task(task);
|
||||
|
@ -83,7 +83,7 @@ mod test {
|
|||
#[test]
|
||||
fn borrow_smoke_test() {
|
||||
run_in_bare_thread(proc() {
|
||||
let task = ~Task::new();
|
||||
let task = box Task::new();
|
||||
Local::put(task);
|
||||
|
||||
unsafe {
|
||||
|
@ -97,7 +97,7 @@ mod test {
|
|||
#[test]
|
||||
fn borrow_with_return() {
|
||||
run_in_bare_thread(proc() {
|
||||
let task = ~Task::new();
|
||||
let task = box Task::new();
|
||||
Local::put(task);
|
||||
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ mod test {
|
|||
#[test]
|
||||
fn try_take() {
|
||||
run_in_bare_thread(proc() {
|
||||
let task = ~Task::new();
|
||||
let task = box Task::new();
|
||||
Local::put(task);
|
||||
|
||||
let t: ~Task = Local::try_take().unwrap();
|
||||
|
|
|
@ -353,7 +353,7 @@ impl BlockedTask {
|
|||
blocked_task_ptr
|
||||
}
|
||||
Shared(arc) => {
|
||||
let blocked_task_ptr: uint = cast::transmute(~arc);
|
||||
let blocked_task_ptr: uint = cast::transmute(box arc);
|
||||
rtassert!(blocked_task_ptr & 0x1 == 0);
|
||||
blocked_task_ptr | 0x1
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn block_and_wake() {
|
||||
let task = ~Task::new();
|
||||
let task = box Task::new();
|
||||
let mut task = BlockedTask::block(task).wake().unwrap();
|
||||
task.destroyed = true;
|
||||
}
|
||||
|
|
|
@ -80,12 +80,12 @@ impl Thread<()> {
|
|||
// 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
|
||||
// so.
|
||||
let packet = ~None;
|
||||
let packet = box None;
|
||||
let packet2: *mut Option<T> = unsafe {
|
||||
*cast::transmute::<&~Option<T>, **mut Option<T>>(&packet)
|
||||
};
|
||||
let main = proc() unsafe { *packet2 = Some(main()); };
|
||||
let native = unsafe { imp::create(stack, ~main) };
|
||||
let native = unsafe { imp::create(stack, box main) };
|
||||
|
||||
Thread {
|
||||
native: native,
|
||||
|
@ -108,7 +108,7 @@ impl Thread<()> {
|
|||
/// stack size for the new thread.
|
||||
pub fn spawn_stack(stack: uint, main: proc():Send) {
|
||||
unsafe {
|
||||
let handle = imp::create(stack, ~main);
|
||||
let handle = imp::create(stack, box main);
|
||||
imp::detach(handle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,14 +96,14 @@ fn tls_smoke_test() {
|
|||
use cast::transmute;
|
||||
unsafe {
|
||||
let mut key = 0;
|
||||
let value = ~20;
|
||||
let value = box 20;
|
||||
create(&mut key);
|
||||
set(key, transmute(value));
|
||||
let value: ~int = transmute(get(key));
|
||||
assert_eq!(value, ~20);
|
||||
let value = ~30;
|
||||
assert_eq!(value, box 20);
|
||||
let value = box 30;
|
||||
set(key, transmute(value));
|
||||
let value: ~int = transmute(get(key));
|
||||
assert_eq!(value, ~30);
|
||||
assert_eq!(value, box 30);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ impl Unwinder {
|
|||
#[no_mangle]
|
||||
fn rust_fail() -> ! {
|
||||
unsafe {
|
||||
let exception = ~uw::_Unwind_Exception {
|
||||
let exception = box uw::_Unwind_Exception {
|
||||
exception_class: rust_exception_class(),
|
||||
exception_cleanup: exception_cleanup,
|
||||
private: [0, ..uw::unwinder_private_data_size],
|
||||
|
@ -346,7 +346,7 @@ pub fn begin_unwind_fmt(msg: &fmt::Arguments, file: &'static str, line: uint) ->
|
|||
// required with the current scheme, and (b) we don't handle
|
||||
// failure + OOM properly anyway (see comment in begin_unwind
|
||||
// below).
|
||||
begin_unwind_inner(~fmt::format(msg), file, line)
|
||||
begin_unwind_inner(box fmt::format(msg), file, line)
|
||||
}
|
||||
|
||||
/// This is the entry point of unwinding for fail!() and assert!().
|
||||
|
@ -360,7 +360,7 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> !
|
|||
// failing.
|
||||
|
||||
// see below for why we do the `Any` coercion here.
|
||||
begin_unwind_inner(~msg, file, line)
|
||||
begin_unwind_inner(box msg, file, line)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2042,7 +2042,7 @@ impl<'a, A> Default for &'a [A] {
|
|||
}
|
||||
|
||||
impl<A> Default for ~[A] {
|
||||
fn default() -> ~[A] { ~[] }
|
||||
fn default() -> ~[A] { box [] }
|
||||
}
|
||||
|
||||
/// Immutable slice iterator
|
||||
|
@ -2361,7 +2361,7 @@ mod tests {
|
|||
fn test_unsafe_ptrs() {
|
||||
unsafe {
|
||||
// Test on-stack copy-from-buf.
|
||||
let a = ~[1, 2, 3];
|
||||
let a = box [1, 2, 3];
|
||||
let mut ptr = a.as_ptr();
|
||||
let b = from_buf(ptr, 3u);
|
||||
assert_eq!(b.len(), 3u);
|
||||
|
@ -2370,7 +2370,7 @@ mod tests {
|
|||
assert_eq!(b[2], 3);
|
||||
|
||||
// Test on-heap copy-from-buf.
|
||||
let c = ~[1, 2, 3, 4, 5];
|
||||
let c = box [1, 2, 3, 4, 5];
|
||||
ptr = c.as_ptr();
|
||||
let d = from_buf(ptr, 5u);
|
||||
assert_eq!(d.len(), 5u);
|
||||
|
@ -2452,91 +2452,91 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get() {
|
||||
let mut a = ~[11];
|
||||
let mut a = box [11];
|
||||
assert_eq!(a.get(1), None);
|
||||
a = ~[11, 12];
|
||||
a = box [11, 12];
|
||||
assert_eq!(a.get(1).unwrap(), &12);
|
||||
a = ~[11, 12, 13];
|
||||
a = box [11, 12, 13];
|
||||
assert_eq!(a.get(1).unwrap(), &12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_head() {
|
||||
let mut a = ~[];
|
||||
let mut a = box [];
|
||||
assert_eq!(a.head(), None);
|
||||
a = ~[11];
|
||||
a = box [11];
|
||||
assert_eq!(a.head().unwrap(), &11);
|
||||
a = ~[11, 12];
|
||||
a = box [11, 12];
|
||||
assert_eq!(a.head().unwrap(), &11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tail() {
|
||||
let mut a = ~[11];
|
||||
let mut a = box [11];
|
||||
assert_eq!(a.tail(), &[]);
|
||||
a = ~[11, 12];
|
||||
a = box [11, 12];
|
||||
assert_eq!(a.tail(), &[12]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_fail]
|
||||
fn test_tail_empty() {
|
||||
let a: ~[int] = ~[];
|
||||
let a: ~[int] = box [];
|
||||
a.tail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tailn() {
|
||||
let mut a = ~[11, 12, 13];
|
||||
let mut a = box [11, 12, 13];
|
||||
assert_eq!(a.tailn(0), &[11, 12, 13]);
|
||||
a = ~[11, 12, 13];
|
||||
a = box [11, 12, 13];
|
||||
assert_eq!(a.tailn(2), &[13]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_fail]
|
||||
fn test_tailn_empty() {
|
||||
let a: ~[int] = ~[];
|
||||
let a: ~[int] = box [];
|
||||
a.tailn(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_init() {
|
||||
let mut a = ~[11];
|
||||
let mut a = box [11];
|
||||
assert_eq!(a.init(), &[]);
|
||||
a = ~[11, 12];
|
||||
a = box [11, 12];
|
||||
assert_eq!(a.init(), &[11]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_fail]
|
||||
fn test_init_empty() {
|
||||
let a: ~[int] = ~[];
|
||||
let a: ~[int] = box [];
|
||||
a.init();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_initn() {
|
||||
let mut a = ~[11, 12, 13];
|
||||
let mut a = box [11, 12, 13];
|
||||
assert_eq!(a.initn(0), &[11, 12, 13]);
|
||||
a = ~[11, 12, 13];
|
||||
a = box [11, 12, 13];
|
||||
assert_eq!(a.initn(2), &[11]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_fail]
|
||||
fn test_initn_empty() {
|
||||
let a: ~[int] = ~[];
|
||||
let a: ~[int] = box [];
|
||||
a.initn(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last() {
|
||||
let mut a = ~[];
|
||||
let mut a = box [];
|
||||
assert_eq!(a.last(), None);
|
||||
a = ~[11];
|
||||
a = box [11];
|
||||
assert_eq!(a.last().unwrap(), &11);
|
||||
a = ~[11, 12];
|
||||
a = box [11, 12];
|
||||
assert_eq!(a.last().unwrap(), &12);
|
||||
}
|
||||
|
||||
|
@ -2558,7 +2558,7 @@ mod tests {
|
|||
assert_eq!(v_b[1], 3);
|
||||
|
||||
// Test on exchange heap.
|
||||
let vec_unique = ~[1, 2, 3, 4, 5, 6];
|
||||
let vec_unique = box [1, 2, 3, 4, 5, 6];
|
||||
let v_d = vec_unique.slice(1u, 6u).to_owned();
|
||||
assert_eq!(v_d.len(), 5u);
|
||||
assert_eq!(v_d[0], 2);
|
||||
|
@ -2692,7 +2692,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_truncate() {
|
||||
let mut v = vec![~6,~5,~4];
|
||||
let mut v = vec![box 6,box 5,box 4];
|
||||
v.truncate(1);
|
||||
let v = v.as_slice();
|
||||
assert_eq!(v.len(), 1);
|
||||
|
@ -2702,7 +2702,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_clear() {
|
||||
let mut v = vec![~6,~5,~4];
|
||||
let mut v = vec![box 6,box 5,box 4];
|
||||
v.clear();
|
||||
assert_eq!(v.len(), 0);
|
||||
// If the unsafe block didn't drop things properly, we blow up here.
|
||||
|
@ -2727,11 +2727,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_dedup_unique() {
|
||||
let mut v0 = vec![~1, ~1, ~2, ~3];
|
||||
let mut v0 = vec![box 1, box 1, box 2, box 3];
|
||||
v0.dedup();
|
||||
let mut v1 = vec![~1, ~2, ~2, ~3];
|
||||
let mut v1 = vec![box 1, box 2, box 2, box 3];
|
||||
v1.dedup();
|
||||
let mut v2 = vec![~1, ~2, ~3, ~3];
|
||||
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
|
||||
|
@ -2741,11 +2741,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_dedup_shared() {
|
||||
let mut v0 = vec![~1, ~1, ~2, ~3];
|
||||
let mut v0 = vec![box 1, box 1, box 2, box 3];
|
||||
v0.dedup();
|
||||
let mut v1 = vec![~1, ~2, ~2, ~3];
|
||||
let mut v1 = vec![box 1, box 2, box 2, box 3];
|
||||
v1.dedup();
|
||||
let mut v2 = vec![~1, ~2, ~3, ~3];
|
||||
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
|
||||
|
@ -2814,15 +2814,15 @@ mod tests {
|
|||
let (min_size, max_opt) = it.size_hint();
|
||||
assert_eq!(min_size, 3*2);
|
||||
assert_eq!(max_opt.unwrap(), 3*2);
|
||||
assert_eq!(it.next(), Some(~[1,2,3]));
|
||||
assert_eq!(it.next(), Some(~[1,3,2]));
|
||||
assert_eq!(it.next(), Some(~[3,1,2]));
|
||||
assert_eq!(it.next(), Some(box [1,2,3]));
|
||||
assert_eq!(it.next(), Some(box [1,3,2]));
|
||||
assert_eq!(it.next(), Some(box [3,1,2]));
|
||||
let (min_size, max_opt) = it.size_hint();
|
||||
assert_eq!(min_size, 3);
|
||||
assert_eq!(max_opt.unwrap(), 3);
|
||||
assert_eq!(it.next(), Some(~[3,2,1]));
|
||||
assert_eq!(it.next(), Some(~[2,3,1]));
|
||||
assert_eq!(it.next(), Some(~[2,1,3]));
|
||||
assert_eq!(it.next(), Some(box [3,2,1]));
|
||||
assert_eq!(it.next(), Some(box [2,3,1]));
|
||||
assert_eq!(it.next(), Some(box [2,1,3]));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
{
|
||||
|
@ -2845,7 +2845,7 @@ mod tests {
|
|||
fn test_position_elem() {
|
||||
assert!([].position_elem(&1).is_none());
|
||||
|
||||
let v1 = ~[1, 2, 3, 3, 2, 5];
|
||||
let v1 = box [1, 2, 3, 3, 2, 5];
|
||||
assert_eq!(v1.position_elem(&1), Some(0u));
|
||||
assert_eq!(v1.position_elem(&2), Some(1u));
|
||||
assert_eq!(v1.position_elem(&5), Some(5u));
|
||||
|
@ -2899,14 +2899,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_reverse() {
|
||||
let mut v: ~[int] = ~[10, 20];
|
||||
let mut v: ~[int] = box [10, 20];
|
||||
assert_eq!(v[0], 10);
|
||||
assert_eq!(v[1], 20);
|
||||
v.reverse();
|
||||
assert_eq!(v[0], 20);
|
||||
assert_eq!(v[1], 10);
|
||||
|
||||
let mut v3: ~[int] = ~[];
|
||||
let mut v3: ~[int] = box [];
|
||||
v3.reverse();
|
||||
assert!(v3.is_empty());
|
||||
}
|
||||
|
@ -2973,39 +2973,39 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_partition() {
|
||||
assert_eq!((~[]).partition(|x: &int| *x < 3), (~[], ~[]));
|
||||
assert_eq!((~[1, 2, 3]).partition(|x: &int| *x < 4), (~[1, 2, 3], ~[]));
|
||||
assert_eq!((~[1, 2, 3]).partition(|x: &int| *x < 2), (~[1], ~[2, 3]));
|
||||
assert_eq!((~[1, 2, 3]).partition(|x: &int| *x < 0), (~[], ~[1, 2, 3]));
|
||||
assert_eq!((box []).partition(|x: &int| *x < 3), (box [], box []));
|
||||
assert_eq!((box [1, 2, 3]).partition(|x: &int| *x < 4), (box [1, 2, 3], box []));
|
||||
assert_eq!((box [1, 2, 3]).partition(|x: &int| *x < 2), (box [1], box [2, 3]));
|
||||
assert_eq!((box [1, 2, 3]).partition(|x: &int| *x < 0), (box [], box [1, 2, 3]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partitioned() {
|
||||
assert_eq!(([]).partitioned(|x: &int| *x < 3), (~[], ~[]))
|
||||
assert_eq!(([1, 2, 3]).partitioned(|x: &int| *x < 4), (~[1, 2, 3], ~[]));
|
||||
assert_eq!(([1, 2, 3]).partitioned(|x: &int| *x < 2), (~[1], ~[2, 3]));
|
||||
assert_eq!(([1, 2, 3]).partitioned(|x: &int| *x < 0), (~[], ~[1, 2, 3]));
|
||||
assert_eq!(([]).partitioned(|x: &int| *x < 3), (box [], box []))
|
||||
assert_eq!(([1, 2, 3]).partitioned(|x: &int| *x < 4), (box [1, 2, 3], box []));
|
||||
assert_eq!(([1, 2, 3]).partitioned(|x: &int| *x < 2), (box [1], box [2, 3]));
|
||||
assert_eq!(([1, 2, 3]).partitioned(|x: &int| *x < 0), (box [], box [1, 2, 3]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_concat() {
|
||||
let v: [~[int], ..0] = [];
|
||||
assert_eq!(v.concat_vec(), ~[]);
|
||||
assert_eq!([~[1], ~[2,3]].concat_vec(), ~[1, 2, 3]);
|
||||
assert_eq!(v.concat_vec(), box []);
|
||||
assert_eq!([box [1], box [2,3]].concat_vec(), box [1, 2, 3]);
|
||||
|
||||
assert_eq!([&[1], &[2,3]].concat_vec(), ~[1, 2, 3]);
|
||||
assert_eq!([&[1], &[2,3]].concat_vec(), box [1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_connect() {
|
||||
let v: [~[int], ..0] = [];
|
||||
assert_eq!(v.connect_vec(&0), ~[]);
|
||||
assert_eq!([~[1], ~[2, 3]].connect_vec(&0), ~[1, 0, 2, 3]);
|
||||
assert_eq!([~[1], ~[2], ~[3]].connect_vec(&0), ~[1, 0, 2, 0, 3]);
|
||||
assert_eq!(v.connect_vec(&0), box []);
|
||||
assert_eq!([box [1], box [2, 3]].connect_vec(&0), box [1, 0, 2, 3]);
|
||||
assert_eq!([box [1], box [2], box [3]].connect_vec(&0), box [1, 0, 2, 0, 3]);
|
||||
|
||||
assert_eq!(v.connect_vec(&0), ~[]);
|
||||
assert_eq!([&[1], &[2, 3]].connect_vec(&0), ~[1, 0, 2, 3]);
|
||||
assert_eq!([&[1], &[2], &[3]].connect_vec(&0), ~[1, 0, 2, 0, 3]);
|
||||
assert_eq!(v.connect_vec(&0), box []);
|
||||
assert_eq!([&[1], &[2, 3]].connect_vec(&0), box [1, 0, 2, 3]);
|
||||
assert_eq!([&[1], &[2], &[3]].connect_vec(&0), box [1, 0, 2, 0, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3100,7 +3100,7 @@ mod tests {
|
|||
fn test_from_fn_fail() {
|
||||
Vec::from_fn(100, |v| {
|
||||
if v == 50 { fail!() }
|
||||
~0
|
||||
box 0
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3124,7 +3124,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
let s = S { f: 0, boxes: (~0, Rc::new(0)) };
|
||||
let s = S { f: 0, boxes: (box 0, Rc::new(0)) };
|
||||
let _ = Vec::from_elem(100, s);
|
||||
}
|
||||
|
||||
|
@ -3137,7 +3137,7 @@ mod tests {
|
|||
if i == 50 {
|
||||
fail!()
|
||||
}
|
||||
(~0, Rc::new(0))
|
||||
(box 0, Rc::new(0))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -3145,7 +3145,8 @@ mod tests {
|
|||
#[should_fail]
|
||||
fn test_permute_fail() {
|
||||
use rc::Rc;
|
||||
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
|
||||
let v = [(box 0, Rc::new(0)), (box 0, Rc::new(0)),
|
||||
(box 0, Rc::new(0)), (box 0, Rc::new(0))];
|
||||
let mut i = 0;
|
||||
for _ in v.permutations() {
|
||||
if i == 2 {
|
||||
|
@ -3288,14 +3289,14 @@ mod tests {
|
|||
#[test]
|
||||
fn test_move_iterator() {
|
||||
use iter::*;
|
||||
let xs = ~[1u,2,3,4,5];
|
||||
let xs = box [1u,2,3,4,5];
|
||||
assert_eq!(xs.move_iter().fold(0, |a: uint, b: uint| 10*a + b), 12345);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_move_rev_iterator() {
|
||||
use iter::*;
|
||||
let xs = ~[1u,2,3,4,5];
|
||||
let xs = box [1u,2,3,4,5];
|
||||
assert_eq!(xs.move_iter().rev().fold(0, |a: uint, b: uint| 10*a + b), 54321);
|
||||
}
|
||||
|
||||
|
@ -3304,18 +3305,18 @@ mod tests {
|
|||
let xs = &[1i,2,3,4,5];
|
||||
|
||||
assert_eq!(xs.split(|x| *x % 2 == 0).collect::<~[&[int]]>(),
|
||||
~[&[1], &[3], &[5]]);
|
||||
box [&[1], &[3], &[5]]);
|
||||
assert_eq!(xs.split(|x| *x == 1).collect::<~[&[int]]>(),
|
||||
~[&[], &[2,3,4,5]]);
|
||||
box [&[], &[2,3,4,5]]);
|
||||
assert_eq!(xs.split(|x| *x == 5).collect::<~[&[int]]>(),
|
||||
~[&[1,2,3,4], &[]]);
|
||||
box [&[1,2,3,4], &[]]);
|
||||
assert_eq!(xs.split(|x| *x == 10).collect::<~[&[int]]>(),
|
||||
~[&[1,2,3,4,5]]);
|
||||
box [&[1,2,3,4,5]]);
|
||||
assert_eq!(xs.split(|_| true).collect::<~[&[int]]>(),
|
||||
~[&[], &[], &[], &[], &[], &[]]);
|
||||
box [&[], &[], &[], &[], &[], &[]]);
|
||||
|
||||
let xs: &[int] = &[];
|
||||
assert_eq!(xs.split(|x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
|
||||
assert_eq!(xs.split(|x| *x == 5).collect::<~[&[int]]>(), box [&[]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3323,14 +3324,14 @@ mod tests {
|
|||
let xs = &[1i,2,3,4,5];
|
||||
|
||||
assert_eq!(xs.splitn(0, |x| *x % 2 == 0).collect::<~[&[int]]>(),
|
||||
~[&[1,2,3,4,5]]);
|
||||
box [&[1,2,3,4,5]]);
|
||||
assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<~[&[int]]>(),
|
||||
~[&[1], &[3,4,5]]);
|
||||
box [&[1], &[3,4,5]]);
|
||||
assert_eq!(xs.splitn(3, |_| true).collect::<~[&[int]]>(),
|
||||
~[&[], &[], &[], &[4,5]]);
|
||||
box [&[], &[], &[], &[4,5]]);
|
||||
|
||||
let xs: &[int] = &[];
|
||||
assert_eq!(xs.splitn(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
|
||||
assert_eq!(xs.splitn(1, |x| *x == 5).collect::<~[&[int]]>(), box [&[]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3338,16 +3339,16 @@ mod tests {
|
|||
let xs = &[1i,2,3,4,5];
|
||||
|
||||
assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<~[&[int]]>(),
|
||||
~[&[5], &[3], &[1]]);
|
||||
box [&[5], &[3], &[1]]);
|
||||
assert_eq!(xs.split(|x| *x == 1).rev().collect::<~[&[int]]>(),
|
||||
~[&[2,3,4,5], &[]]);
|
||||
box [&[2,3,4,5], &[]]);
|
||||
assert_eq!(xs.split(|x| *x == 5).rev().collect::<~[&[int]]>(),
|
||||
~[&[], &[1,2,3,4]]);
|
||||
box [&[], &[1,2,3,4]]);
|
||||
assert_eq!(xs.split(|x| *x == 10).rev().collect::<~[&[int]]>(),
|
||||
~[&[1,2,3,4,5]]);
|
||||
box [&[1,2,3,4,5]]);
|
||||
|
||||
let xs: &[int] = &[];
|
||||
assert_eq!(xs.split(|x| *x == 5).rev().collect::<~[&[int]]>(), ~[&[]]);
|
||||
assert_eq!(xs.split(|x| *x == 5).rev().collect::<~[&[int]]>(), box [&[]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3355,22 +3356,22 @@ mod tests {
|
|||
let xs = &[1,2,3,4,5];
|
||||
|
||||
assert_eq!(xs.rsplitn(0, |x| *x % 2 == 0).collect::<~[&[int]]>(),
|
||||
~[&[1,2,3,4,5]]);
|
||||
box [&[1,2,3,4,5]]);
|
||||
assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<~[&[int]]>(),
|
||||
~[&[5], &[1,2,3]]);
|
||||
box [&[5], &[1,2,3]]);
|
||||
assert_eq!(xs.rsplitn(3, |_| true).collect::<~[&[int]]>(),
|
||||
~[&[], &[], &[], &[1,2]]);
|
||||
box [&[], &[], &[], &[1,2]]);
|
||||
|
||||
let xs: &[int] = &[];
|
||||
assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<~[&[int]]>(), ~[&[]]);
|
||||
assert_eq!(xs.rsplitn(1, |x| *x == 5).collect::<~[&[int]]>(), box [&[]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_windowsator() {
|
||||
let v = &[1i,2,3,4];
|
||||
|
||||
assert_eq!(v.windows(2).collect::<~[&[int]]>(), ~[&[1,2], &[2,3], &[3,4]]);
|
||||
assert_eq!(v.windows(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[2,3,4]]);
|
||||
assert_eq!(v.windows(2).collect::<~[&[int]]>(), box [&[1,2], &[2,3], &[3,4]]);
|
||||
assert_eq!(v.windows(3).collect::<~[&[int]]>(), box [&[1i,2,3], &[2,3,4]]);
|
||||
assert!(v.windows(6).next().is_none());
|
||||
}
|
||||
|
||||
|
@ -3385,11 +3386,11 @@ mod tests {
|
|||
fn test_chunksator() {
|
||||
let v = &[1i,2,3,4,5];
|
||||
|
||||
assert_eq!(v.chunks(2).collect::<~[&[int]]>(), ~[&[1i,2], &[3,4], &[5]]);
|
||||
assert_eq!(v.chunks(3).collect::<~[&[int]]>(), ~[&[1i,2,3], &[4,5]]);
|
||||
assert_eq!(v.chunks(6).collect::<~[&[int]]>(), ~[&[1i,2,3,4,5]]);
|
||||
assert_eq!(v.chunks(2).collect::<~[&[int]]>(), box [&[1i,2], &[3,4], &[5]]);
|
||||
assert_eq!(v.chunks(3).collect::<~[&[int]]>(), box [&[1i,2,3], &[4,5]]);
|
||||
assert_eq!(v.chunks(6).collect::<~[&[int]]>(), box [&[1i,2,3,4,5]]);
|
||||
|
||||
assert_eq!(v.chunks(2).rev().collect::<~[&[int]]>(), ~[&[5i], &[3,4], &[1,2]]);
|
||||
assert_eq!(v.chunks(2).rev().collect::<~[&[int]]>(), box [&[5i], &[3,4], &[1,2]]);
|
||||
let mut it = v.chunks(2);
|
||||
assert_eq!(it.indexable(), 3);
|
||||
assert_eq!(it.idx(0).unwrap(), &[1,2]);
|
||||
|
@ -3408,19 +3409,19 @@ mod tests {
|
|||
#[test]
|
||||
fn test_move_from() {
|
||||
let mut a = [1,2,3,4,5];
|
||||
let b = ~[6,7,8];
|
||||
let b = box [6,7,8];
|
||||
assert_eq!(a.move_from(b, 0, 3), 3);
|
||||
assert!(a == [6,7,8,4,5]);
|
||||
let mut a = [7,2,8,1];
|
||||
let b = ~[3,1,4,1,5,9];
|
||||
let b = box [3,1,4,1,5,9];
|
||||
assert_eq!(a.move_from(b, 0, 6), 4);
|
||||
assert!(a == [3,1,4,1]);
|
||||
let mut a = [1,2,3,4];
|
||||
let b = ~[5,6,7,8,9,0];
|
||||
let b = box [5,6,7,8,9,0];
|
||||
assert_eq!(a.move_from(b, 2, 3), 1);
|
||||
assert!(a == [7,2,3,4]);
|
||||
let mut a = [1,2,3,4,5];
|
||||
let b = ~[5,6,7,8,9,0];
|
||||
let b = box [5,6,7,8,9,0];
|
||||
assert_eq!(a.mut_slice(2,4).move_from(b,1,6), 2);
|
||||
assert!(a == [1,2,6,7,5]);
|
||||
}
|
||||
|
@ -3453,11 +3454,11 @@ mod tests {
|
|||
assert_eq!(format!("{}", x.as_slice()), x_str);
|
||||
})
|
||||
)
|
||||
let empty: ~[int] = ~[];
|
||||
let empty: ~[int] = box [];
|
||||
test_show_vec!(empty, "[]".to_owned());
|
||||
test_show_vec!(~[1], "[1]".to_owned());
|
||||
test_show_vec!(~[1, 2, 3], "[1, 2, 3]".to_owned());
|
||||
test_show_vec!(~[~[], ~[1u], ~[1u, 1u]], "[[], [1], [1, 1]]".to_owned());
|
||||
test_show_vec!(box [1], "[1]".to_owned());
|
||||
test_show_vec!(box [1, 2, 3], "[1, 2, 3]".to_owned());
|
||||
test_show_vec!(box [box [], box [1u], box [1u, 1u]], "[[], [1], [1, 1]]".to_owned());
|
||||
|
||||
let empty_mut: &mut [int] = &mut[];
|
||||
test_show_vec!(empty_mut, "[]".to_owned());
|
||||
|
@ -3890,7 +3891,7 @@ mod bench {
|
|||
#[bench]
|
||||
fn zero_1kb_fixed_repeat(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~[0u8, ..1024]
|
||||
box [0u8, ..1024]
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ impl FromStr for ~str {
|
|||
/// Fails if invalid UTF-8
|
||||
pub fn from_byte(b: u8) -> ~str {
|
||||
assert!(b < 128u8);
|
||||
unsafe { ::cast::transmute(~[b]) }
|
||||
unsafe { ::cast::transmute(box [b]) }
|
||||
}
|
||||
|
||||
/// Convert a char to a string
|
||||
|
@ -1387,7 +1387,7 @@ pub mod raw {
|
|||
}
|
||||
|
||||
/// Converts a byte to a string.
|
||||
pub unsafe fn from_byte(u: u8) -> ~str { from_utf8_owned(~[u]) }
|
||||
pub unsafe fn from_byte(u: u8) -> ~str { from_utf8_owned(box [u]) }
|
||||
|
||||
/// Form a slice from a C string. Unsafe because the caller must ensure the
|
||||
/// C string has the static lifetime, or else the return value may be
|
||||
|
@ -1448,7 +1448,7 @@ pub mod raw {
|
|||
#[test]
|
||||
fn test_from_buf_len() {
|
||||
unsafe {
|
||||
let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
|
||||
let a = box [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8];
|
||||
let b = a.as_ptr();
|
||||
let c = from_buf_len(b, 3u);
|
||||
assert_eq!(c, "AAA".to_owned());
|
||||
|
@ -3342,7 +3342,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_raw_from_c_str() {
|
||||
unsafe {
|
||||
let a = ~[65, 65, 65, 65, 65, 65, 65, 0];
|
||||
let a = box [65, 65, 65, 65, 65, 65, 65, 0];
|
||||
let b = a.as_ptr();
|
||||
let c = raw::from_c_str(b);
|
||||
assert_eq!(c, "AAAAAAA".to_owned());
|
||||
|
@ -3456,13 +3456,13 @@ mod tests {
|
|||
fn test_utf16() {
|
||||
let pairs =
|
||||
[("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n".to_owned(),
|
||||
~[0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16,
|
||||
box [0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16,
|
||||
0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16,
|
||||
0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16,
|
||||
0xd800_u16, 0xdf30_u16, 0x000a_u16]),
|
||||
|
||||
("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n".to_owned(),
|
||||
~[0xd801_u16, 0xdc12_u16, 0xd801_u16,
|
||||
box [0xd801_u16, 0xdc12_u16, 0xd801_u16,
|
||||
0xdc49_u16, 0xd801_u16, 0xdc2e_u16, 0xd801_u16,
|
||||
0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16,
|
||||
0xdc4b_u16, 0x0020_u16, 0xd801_u16, 0xdc0f_u16,
|
||||
|
@ -3470,7 +3470,7 @@ mod tests {
|
|||
0x000a_u16]),
|
||||
|
||||
("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n".to_owned(),
|
||||
~[0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16,
|
||||
box [0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16,
|
||||
0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04_u16,
|
||||
0xd800_u16, 0xdf11_u16, 0xd800_u16, 0xdf09_u16,
|
||||
0x00b7_u16, 0xd800_u16, 0xdf0c_u16, 0xd800_u16,
|
||||
|
@ -3479,7 +3479,7 @@ mod tests {
|
|||
0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]),
|
||||
|
||||
("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n".to_owned(),
|
||||
~[0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16,
|
||||
box [0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16,
|
||||
0xd801_u16, 0xdc88_u16, 0xd801_u16, 0xdc91_u16,
|
||||
0xd801_u16, 0xdc9b_u16, 0xd801_u16, 0xdc92_u16,
|
||||
0x0020_u16, 0xd801_u16, 0xdc95_u16, 0xd801_u16,
|
||||
|
@ -3492,7 +3492,7 @@ mod tests {
|
|||
0x000a_u16 ]),
|
||||
// Issue #12318, even-numbered non-BMP planes
|
||||
("\U00020000".to_owned(),
|
||||
~[0xD840, 0xDC00])];
|
||||
box [0xD840, 0xDC00])];
|
||||
|
||||
for p in pairs.iter() {
|
||||
let (s, u) = (*p).clone();
|
||||
|
@ -3558,7 +3558,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_char_at() {
|
||||
let s = "ศไทย中华Việt Nam".to_owned();
|
||||
let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
|
||||
let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
|
||||
let mut pos = 0;
|
||||
for ch in v.iter() {
|
||||
assert!(s.char_at(pos) == *ch);
|
||||
|
@ -3569,7 +3569,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_char_at_reverse() {
|
||||
let s = "ศไทย中华Việt Nam".to_owned();
|
||||
let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
|
||||
let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
|
||||
let mut pos = s.len();
|
||||
for ch in v.iter().rev() {
|
||||
assert!(s.char_at_reverse(pos) == *ch);
|
||||
|
@ -3652,7 +3652,7 @@ mod tests {
|
|||
fn test_iterator() {
|
||||
use iter::*;
|
||||
let s = "ศไทย中华Việt Nam".to_owned();
|
||||
let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
|
||||
let v = box ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
|
||||
|
||||
let mut pos = 0;
|
||||
let mut it = s.chars();
|
||||
|
@ -3668,7 +3668,7 @@ mod tests {
|
|||
fn test_rev_iterator() {
|
||||
use iter::*;
|
||||
let s = "ศไทย中华Việt Nam".to_owned();
|
||||
let v = ~['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ'];
|
||||
let v = box ['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ'];
|
||||
|
||||
let mut pos = 0;
|
||||
let mut it = s.chars().rev();
|
||||
|
@ -3761,33 +3761,33 @@ mod tests {
|
|||
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
|
||||
|
||||
let split: ~[&str] = data.split(' ').collect();
|
||||
assert_eq!( split, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
assert_eq!( split, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
|
||||
let mut rsplit: ~[&str] = data.split(' ').rev().collect();
|
||||
rsplit.reverse();
|
||||
assert_eq!(rsplit, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
assert_eq!(rsplit, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
|
||||
let split: ~[&str] = data.split(|c: char| c == ' ').collect();
|
||||
assert_eq!( split, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
assert_eq!( split, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
|
||||
let mut rsplit: ~[&str] = data.split(|c: char| c == ' ').rev().collect();
|
||||
rsplit.reverse();
|
||||
assert_eq!(rsplit, ~["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
assert_eq!(rsplit, box ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
|
||||
// Unicode
|
||||
let split: ~[&str] = data.split('ä').collect();
|
||||
assert_eq!( split, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
assert_eq!( split, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
|
||||
let mut rsplit: ~[&str] = data.split('ä').rev().collect();
|
||||
rsplit.reverse();
|
||||
assert_eq!(rsplit, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
assert_eq!(rsplit, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
|
||||
let split: ~[&str] = data.split(|c: char| c == 'ä').collect();
|
||||
assert_eq!( split, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
assert_eq!( split, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
|
||||
let mut rsplit: ~[&str] = data.split(|c: char| c == 'ä').rev().collect();
|
||||
rsplit.reverse();
|
||||
assert_eq!(rsplit, ~["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
assert_eq!(rsplit, box ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3795,17 +3795,17 @@ mod tests {
|
|||
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
|
||||
|
||||
let split: ~[&str] = data.splitn(' ', 3).collect();
|
||||
assert_eq!(split, ~["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
|
||||
assert_eq!(split, box ["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
|
||||
|
||||
let split: ~[&str] = data.splitn(|c: char| c == ' ', 3).collect();
|
||||
assert_eq!(split, ~["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
|
||||
assert_eq!(split, box ["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
|
||||
|
||||
// Unicode
|
||||
let split: ~[&str] = data.splitn('ä', 3).collect();
|
||||
assert_eq!(split, ~["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
|
||||
assert_eq!(split, box ["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
|
||||
|
||||
let split: ~[&str] = data.splitn(|c: char| c == 'ä', 3).collect();
|
||||
assert_eq!(split, ~["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
|
||||
assert_eq!(split, box ["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3814,20 +3814,20 @@ mod tests {
|
|||
|
||||
let mut split: ~[&str] = data.rsplitn(' ', 3).collect();
|
||||
split.reverse();
|
||||
assert_eq!(split, ~["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
assert_eq!(split, box ["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
|
||||
let mut split: ~[&str] = data.rsplitn(|c: char| c == ' ', 3).collect();
|
||||
split.reverse();
|
||||
assert_eq!(split, ~["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
assert_eq!(split, box ["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
|
||||
|
||||
// Unicode
|
||||
let mut split: ~[&str] = data.rsplitn('ä', 3).collect();
|
||||
split.reverse();
|
||||
assert_eq!(split, ~["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
assert_eq!(split, box ["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
|
||||
let mut split: ~[&str] = data.rsplitn(|c: char| c == 'ä', 3).collect();
|
||||
split.reverse();
|
||||
assert_eq!(split, ~["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
assert_eq!(split, box ["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3835,10 +3835,10 @@ mod tests {
|
|||
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
|
||||
|
||||
let split: ~[&str] = data.split('\n').collect();
|
||||
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb", ""]);
|
||||
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb", ""]);
|
||||
|
||||
let split: ~[&str] = data.split_terminator('\n').collect();
|
||||
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb"]);
|
||||
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3847,18 +3847,18 @@ mod tests {
|
|||
|
||||
let mut split: ~[&str] = data.split('\n').rev().collect();
|
||||
split.reverse();
|
||||
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb", ""]);
|
||||
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb", ""]);
|
||||
|
||||
let mut split: ~[&str] = data.split_terminator('\n').rev().collect();
|
||||
split.reverse();
|
||||
assert_eq!(split, ~["", "Märy häd ä little lämb", "Little lämb"]);
|
||||
assert_eq!(split, box ["", "Märy häd ä little lämb", "Little lämb"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_words() {
|
||||
let data = "\n \tMäry häd\tä little lämb\nLittle lämb\n";
|
||||
let words: ~[&str] = data.words().collect();
|
||||
assert_eq!(words, ~["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
|
||||
assert_eq!(words, box ["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3893,11 +3893,11 @@ mod tests {
|
|||
fn test_lines() {
|
||||
let data = "\nMäry häd ä little lämb\n\nLittle lämb\n";
|
||||
let lines: ~[&str] = data.lines().collect();
|
||||
assert_eq!(lines, ~["", "Märy häd ä little lämb", "", "Little lämb"]);
|
||||
assert_eq!(lines, box ["", "Märy häd ä little lämb", "", "Little lämb"]);
|
||||
|
||||
let data = "\nMäry häd ä little lämb\n\nLittle lämb"; // no trailing \n
|
||||
let lines: ~[&str] = data.lines().collect();
|
||||
assert_eq!(lines, ~["", "Märy häd ä little lämb", "", "Little lämb"]);
|
||||
assert_eq!(lines, box ["", "Märy häd ä little lämb", "", "Little lämb"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -3906,20 +3906,20 @@ mod tests {
|
|||
let v: ~[&str] = s.split_str(sep).collect();
|
||||
assert_eq!(v, u);
|
||||
}
|
||||
t("--1233345--", "12345", ~["--1233345--"]);
|
||||
t("abc::hello::there", "::", ~["abc", "hello", "there"]);
|
||||
t("::hello::there", "::", ~["", "hello", "there"]);
|
||||
t("hello::there::", "::", ~["hello", "there", ""]);
|
||||
t("::hello::there::", "::", ~["", "hello", "there", ""]);
|
||||
t("ประเทศไทย中华Việt Nam", "中华", ~["ประเทศไทย", "Việt Nam"]);
|
||||
t("zzXXXzzYYYzz", "zz", ~["", "XXX", "YYY", ""]);
|
||||
t("zzXXXzYYYz", "XXX", ~["zz", "zYYYz"]);
|
||||
t(".XXX.YYY.", ".", ~["", "XXX", "YYY", ""]);
|
||||
t("", ".", ~[""]);
|
||||
t("zz", "zz", ~["",""]);
|
||||
t("ok", "z", ~["ok"]);
|
||||
t("zzz", "zz", ~["","z"]);
|
||||
t("zzzzz", "zz", ~["","","z"]);
|
||||
t("--1233345--", "12345", box ["--1233345--"]);
|
||||
t("abc::hello::there", "::", box ["abc", "hello", "there"]);
|
||||
t("::hello::there", "::", box ["", "hello", "there"]);
|
||||
t("hello::there::", "::", box ["hello", "there", ""]);
|
||||
t("::hello::there::", "::", box ["", "hello", "there", ""]);
|
||||
t("ประเทศไทย中华Việt Nam", "中华", box ["ประเทศไทย", "Việt Nam"]);
|
||||
t("zzXXXzzYYYzz", "zz", box ["", "XXX", "YYY", ""]);
|
||||
t("zzXXXzYYYz", "XXX", box ["zz", "zYYYz"]);
|
||||
t(".XXX.YYY.", ".", box ["", "XXX", "YYY", ""]);
|
||||
t("", ".", box [""]);
|
||||
t("zz", "zz", box ["",""]);
|
||||
t("ok", "z", box ["ok"]);
|
||||
t("zzz", "zz", box ["","z"]);
|
||||
t("zzzzz", "zz", box ["","","z"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -45,7 +45,7 @@ struct ArcData<T> {
|
|||
}
|
||||
|
||||
unsafe fn new_inner<T: Send>(data: T, refcount: uint) -> *mut ArcData<T> {
|
||||
let data = ~ArcData {
|
||||
let data = box ArcData {
|
||||
count: AtomicUint::new(refcount),
|
||||
data: Unsafe::new(data)
|
||||
};
|
||||
|
@ -71,7 +71,7 @@ impl<T: Send> UnsafeArc<T> {
|
|||
pub fn newN(data: T, num_handles: uint) -> ~[UnsafeArc<T>] {
|
||||
unsafe {
|
||||
if num_handles == 0 {
|
||||
~[] // need to free data here
|
||||
box [] // need to free data here
|
||||
} else {
|
||||
let ptr = new_inner(data, num_handles);
|
||||
let v = Vec::from_fn(num_handles, |_| UnsafeArc { data: ptr });
|
||||
|
|
|
@ -894,36 +894,36 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn option_swap() {
|
||||
let p = AtomicOption::new(~1);
|
||||
let a = ~2;
|
||||
let p = AtomicOption::new(box 1);
|
||||
let a = box 2;
|
||||
|
||||
let b = p.swap(a, SeqCst);
|
||||
|
||||
assert_eq!(b, Some(~1));
|
||||
assert_eq!(p.take(SeqCst), Some(~2));
|
||||
assert_eq!(b, Some(box 1));
|
||||
assert_eq!(p.take(SeqCst), Some(box 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn option_take() {
|
||||
let p = AtomicOption::new(~1);
|
||||
let p = AtomicOption::new(box 1);
|
||||
|
||||
assert_eq!(p.take(SeqCst), Some(~1));
|
||||
assert_eq!(p.take(SeqCst), Some(box 1));
|
||||
assert_eq!(p.take(SeqCst), None);
|
||||
|
||||
let p2 = ~2;
|
||||
let p2 = box 2;
|
||||
p.swap(p2, SeqCst);
|
||||
|
||||
assert_eq!(p.take(SeqCst), Some(~2));
|
||||
assert_eq!(p.take(SeqCst), Some(box 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn option_fill() {
|
||||
let p = AtomicOption::new(~1);
|
||||
assert!(p.fill(~2, SeqCst).is_some()); // should fail; shouldn't leak!
|
||||
assert_eq!(p.take(SeqCst), Some(~1));
|
||||
let p = AtomicOption::new(box 1);
|
||||
assert!(p.fill(box 2, SeqCst).is_some()); // should fail; shouldn't leak!
|
||||
assert_eq!(p.take(SeqCst), Some(box 1));
|
||||
|
||||
assert!(p.fill(~2, SeqCst).is_none()); // shouldn't fail
|
||||
assert_eq!(p.take(SeqCst), Some(~2));
|
||||
assert!(p.fill(box 2, SeqCst).is_none()); // shouldn't fail
|
||||
assert_eq!(p.take(SeqCst), Some(box 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -159,7 +159,7 @@ impl<T: Send> BufferPool<T> {
|
|||
self.pool.with(|pool| {
|
||||
match pool.iter().position(|x| x.size() >= (1 << bits)) {
|
||||
Some(i) => pool.remove(i).unwrap(),
|
||||
None => ~Buffer::new(bits)
|
||||
None => box Buffer::new(bits)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ impl<T: Send> Deque<T> {
|
|||
// continue to be read after we flag this buffer for reclamation.
|
||||
unsafe fn swap_buffer(&mut self, b: int, old: *mut Buffer<T>,
|
||||
buf: Buffer<T>) -> *mut Buffer<T> {
|
||||
let newbuf: *mut Buffer<T> = cast::transmute(~buf);
|
||||
let newbuf: *mut Buffer<T> = cast::transmute(box buf);
|
||||
self.array.store(newbuf, SeqCst);
|
||||
let ss = (*newbuf).size();
|
||||
self.bottom.store(b + ss, SeqCst);
|
||||
|
@ -474,7 +474,7 @@ mod tests {
|
|||
fn stampede(mut w: Worker<~int>, s: Stealer<~int>,
|
||||
nthreads: int, amt: uint) {
|
||||
for _ in range(0, amt) {
|
||||
w.push(~20);
|
||||
w.push(box 20);
|
||||
}
|
||||
let mut remaining = AtomicUint::new(amt);
|
||||
let unsafe_remaining: *mut AtomicUint = &mut remaining;
|
||||
|
@ -603,7 +603,7 @@ mod tests {
|
|||
|
||||
let (threads, hits) = slice::unzip(range(0, NTHREADS).map(|_| {
|
||||
let s = s.clone();
|
||||
let unique_box = ~AtomicUint::new(0);
|
||||
let unique_box = box AtomicUint::new(0);
|
||||
let thread_box = unsafe {
|
||||
*cast::transmute::<&~AtomicUint,**mut AtomicUint>(&unique_box)
|
||||
};
|
||||
|
|
|
@ -73,7 +73,7 @@ pub struct Queue<T> {
|
|||
|
||||
impl<T> Node<T> {
|
||||
unsafe fn new(v: Option<T>) -> *mut Node<T> {
|
||||
cast::transmute(~Node {
|
||||
cast::transmute(box Node {
|
||||
next: AtomicPtr::new(0 as *mut Node<T>),
|
||||
value: v,
|
||||
})
|
||||
|
@ -163,8 +163,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_full() {
|
||||
let mut q = Queue::new();
|
||||
q.push(~1);
|
||||
q.push(~2);
|
||||
q.push(box 1);
|
||||
q.push(box 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -73,7 +73,7 @@ pub struct Queue<T> {
|
|||
impl<T: Send> Node<T> {
|
||||
fn new() -> *mut Node<T> {
|
||||
unsafe {
|
||||
cast::transmute(~Node {
|
||||
cast::transmute(box Node {
|
||||
value: None,
|
||||
next: AtomicPtr::new(0 as *mut Node<T>),
|
||||
})
|
||||
|
@ -247,8 +247,8 @@ mod test {
|
|||
#[test]
|
||||
fn drop_full() {
|
||||
let mut q = Queue::new(0);
|
||||
q.push(~1);
|
||||
q.push(~2);
|
||||
q.push(box 1);
|
||||
q.push(box 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -418,7 +418,7 @@ fn test_spawn_sched_childs_on_default_sched() {
|
|||
fn avoid_copying_the_body(spawnfn: |v: proc():Send|) {
|
||||
let (tx, rx) = channel::<uint>();
|
||||
|
||||
let x = ~1;
|
||||
let x = box 1;
|
||||
let x_in_parent = (&*x) as *int as uint;
|
||||
|
||||
spawnfn(proc() {
|
||||
|
@ -507,7 +507,7 @@ fn test_try_fail_message_owned_str() {
|
|||
#[test]
|
||||
fn test_try_fail_message_any() {
|
||||
match try(proc() {
|
||||
fail!(~413u16 as ~Any:Send);
|
||||
fail!(box 413u16 as ~Any:Send);
|
||||
}) {
|
||||
Err(e) => {
|
||||
type T = ~Any:Send;
|
||||
|
|
|
@ -51,11 +51,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_vectors() {
|
||||
let x: ~[int] = ~[];
|
||||
let x: ~[int] = box [];
|
||||
assert_eq!(x.to_str(), "[]".to_owned());
|
||||
assert_eq!((~[1]).to_str(), "[1]".to_owned());
|
||||
assert_eq!((~[1, 2, 3]).to_str(), "[1, 2, 3]".to_owned());
|
||||
assert!((~[~[], ~[1], ~[1, 1]]).to_str() ==
|
||||
assert_eq!((box [1]).to_str(), "[1]".to_owned());
|
||||
assert_eq!((box [1, 2, 3]).to_str(), "[1, 2, 3]".to_owned());
|
||||
assert!((box [box [], box [1], box [1, 1]]).to_str() ==
|
||||
"[[], [1], [1, 1]]".to_owned());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ impl DynamicLibrary {
|
|||
} else {
|
||||
("LD_LIBRARY_PATH", ':' as u8)
|
||||
};
|
||||
let newenv = os::getenv_as_bytes(envvar).unwrap_or(~[]);
|
||||
let newenv = os::getenv_as_bytes(envvar).unwrap_or(box []);
|
||||
let newenv = newenv + &[sep] + path.as_vec();
|
||||
os::setenv(envvar, str::from_utf8(newenv).unwrap());
|
||||
}
|
||||
|
|
|
@ -44,9 +44,9 @@ fn test_run_in_bare_thread() {
|
|||
#[test]
|
||||
fn test_run_in_bare_thread_exchange() {
|
||||
// Does the exchange heap work without the runtime?
|
||||
let i = ~100;
|
||||
let i = box 100;
|
||||
run_in_bare_thread(proc() {
|
||||
assert!(i == ~100);
|
||||
assert!(i == box 100);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ mod tests {
|
|||
let num_tasks = 10;
|
||||
let count = 10;
|
||||
|
||||
let total = Exclusive::new(~0);
|
||||
let total = Exclusive::new(box 0);
|
||||
|
||||
for _ in range(0u, num_tasks) {
|
||||
let total = total.clone();
|
||||
|
|
|
@ -1585,8 +1585,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clone_from() {
|
||||
let mut v = vec!();
|
||||
let three = vec!(~1, ~2, ~3);
|
||||
let two = vec!(~4, ~5);
|
||||
let three = vec!(box 1, box 2, box 3);
|
||||
let two = vec!(box 4, box 5);
|
||||
// zero, long
|
||||
v.clone_from(&three);
|
||||
assert_eq!(v, three);
|
||||
|
|
|
@ -70,7 +70,7 @@ impl<T: Share + Send> Arc<T> {
|
|||
pub fn new(data: T) -> Arc<T> {
|
||||
// Start the weak pointer count as 1 which is the weak pointer that's
|
||||
// held by all the strong pointers (kinda), see std/rc.rs for more info
|
||||
let x = ~ArcInner {
|
||||
let x = box ArcInner {
|
||||
strong: atomics::AtomicUint::new(1),
|
||||
weak: atomics::AtomicUint::new(1),
|
||||
data: data,
|
||||
|
|
|
@ -109,7 +109,7 @@ struct SemGuard<'a, Q> {
|
|||
impl<Q: Send> Sem<Q> {
|
||||
fn new(count: int, q: Q) -> Sem<Q> {
|
||||
let inner = unsafe {
|
||||
cast::transmute(~SemInner {
|
||||
cast::transmute(box SemInner {
|
||||
waiters: WaitQueue::new(),
|
||||
count: count,
|
||||
blocked: q,
|
||||
|
@ -726,7 +726,7 @@ mod tests {
|
|||
let (tx, rx) = channel();
|
||||
let m = Arc::new(Mutex::new());
|
||||
let m2 = m.clone();
|
||||
let mut sharedstate = ~0;
|
||||
let mut sharedstate = box 0;
|
||||
{
|
||||
let ptr: *mut int = &mut *sharedstate;
|
||||
task::spawn(proc() {
|
||||
|
@ -895,7 +895,7 @@ mod tests {
|
|||
// mutex mutual exclusion test, a ways above.
|
||||
let (tx, rx) = channel();
|
||||
let x2 = x.clone();
|
||||
let mut sharedstate = ~0;
|
||||
let mut sharedstate = box 0;
|
||||
{
|
||||
let ptr: *int = &*sharedstate;
|
||||
task::spawn(proc() {
|
||||
|
|
|
@ -177,7 +177,7 @@ pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
|
|||
}
|
||||
|
||||
pub fn default_handler() -> Handler {
|
||||
mk_handler(~EmitterWriter::stderr())
|
||||
mk_handler(box EmitterWriter::stderr())
|
||||
}
|
||||
|
||||
pub fn mk_handler(e: ~Emitter:Send) -> Handler {
|
||||
|
@ -262,11 +262,11 @@ impl EmitterWriter {
|
|||
if stderr.get_ref().isatty() {
|
||||
let dst = match term::Terminal::new(stderr.unwrap()) {
|
||||
Ok(t) => Terminal(t),
|
||||
Err(..) => Raw(~io::stderr()),
|
||||
Err(..) => Raw(box io::stderr()),
|
||||
};
|
||||
EmitterWriter { dst: dst }
|
||||
} else {
|
||||
EmitterWriter { dst: Raw(~stderr) }
|
||||
EmitterWriter { dst: Raw(box stderr) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue