Skip to content

Replace many uses of ~ with box. #11779 #13773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/etc/emacs/rust-mode.el
Original file line number Diff line number Diff line change
@@ -169,7 +169,7 @@
;; Font-locking definitions and helpers
(defconst rust-mode-keywords
'("as"
"break"
"box" "break"
"continue" "crate"
"do"
"else" "enum" "extern"
4 changes: 2 additions & 2 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
@@ -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 ),
}
16 changes: 8 additions & 8 deletions src/libcollections/btree.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
20 changes: 10 additions & 10 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 2 additions & 2 deletions src/libcollections/lru_cache.rs
Original file line number Diff line number Diff line change
@@ -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))
}
10 changes: 5 additions & 5 deletions src/libcollections/priority_queue.rs
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 2 additions & 2 deletions src/libcollections/smallintmap.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}

2 changes: 1 addition & 1 deletion src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion src/libcollections/trie.rs
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 3 additions & 3 deletions src/libgreen/basic.rs
Original file line number Diff line number Diff line change
@@ -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 }
10 changes: 5 additions & 5 deletions src/libgreen/context.rs
Original file line number Diff line number Diff line change
@@ -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,
4 changes: 2 additions & 2 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
@@ -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(),
10 changes: 5 additions & 5 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}

4 changes: 2 additions & 2 deletions src/libgreen/simple.rs
Original file line number Diff line number Diff line change
@@ -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,
});
4 changes: 2 additions & 2 deletions src/libgreen/task.rs
Original file line number Diff line number Diff line change
@@ -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()),
}
}

4 changes: 2 additions & 2 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
@@ -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() {
2 changes: 1 addition & 1 deletion src/libnative/io/file_unix.rs
Original file line number Diff line number Diff line change
@@ -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
}
}

Loading