Skip to content

Commit a5be12c

Browse files
committed
Replace most ~exprs with 'box'. #11779
1 parent a67307e commit a5be12c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+630
-623
lines changed

src/libarena/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ mod tests {
517517
#[bench]
518518
pub fn bench_copy_nonarena(b: &mut Bencher) {
519519
b.iter(|| {
520-
~Point {
520+
box Point {
521521
x: 1,
522522
y: 2,
523523
z: 3,
@@ -569,7 +569,7 @@ mod tests {
569569
#[bench]
570570
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
571571
b.iter(|| {
572-
~Noncopy {
572+
box Noncopy {
573573
string: "hello world".to_owned(),
574574
array: vec!( 1, 2, 3, 4, 5 ),
575575
}

src/libcollections/btree.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ impl<K: Clone + TotalOrd, V: Clone> Leaf<K, V> {
377377
== Less);
378378
let branch_return = Node::new_branch(vec!(BranchElt::new(midpoint.key.clone(),
379379
midpoint.value.clone(),
380-
~Node::new_leaf(left_leaf))),
381-
~Node::new_leaf(right_leaf));
380+
box Node::new_leaf(left_leaf))),
381+
box Node::new_leaf(right_leaf));
382382
return (branch_return, true);
383383
}
384384
(Node::new_leaf(self.elts.clone()), true)
@@ -540,10 +540,10 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
540540
//so we can return false.
541541
LeafNode(..) => {
542542
if index.unwrap() == self.elts.len() {
543-
self.rightmost_child = ~new_branch.clone();
543+
self.rightmost_child = box new_branch.clone();
544544
}
545545
else {
546-
self.elts.get_mut(index.unwrap()).left = ~new_branch.clone();
546+
self.elts.get_mut(index.unwrap()).left = box new_branch.clone();
547547
}
548548
return (Node::new_branch(self.clone().elts,
549549
self.clone().rightmost_child),
@@ -561,10 +561,10 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
561561
//and return it, saying we have inserted a new element.
562562
LeafNode(..) => {
563563
if index.unwrap() == self.elts.len() {
564-
self.rightmost_child = ~new_branch;
564+
self.rightmost_child = box new_branch;
565565
}
566566
else {
567-
self.elts.get_mut(index.unwrap()).left = ~new_branch;
567+
self.elts.get_mut(index.unwrap()).left = box new_branch;
568568
}
569569
return (Node::new_branch(self.clone().elts,
570570
self.clone().rightmost_child),
@@ -604,9 +604,9 @@ impl<K: Clone + TotalOrd, V: Clone> Branch<K, V> {
604604
new_branch = Node::new_branch(
605605
vec!(BranchElt::new(midpoint.clone().key,
606606
midpoint.clone().value,
607-
~Node::new_branch(new_left,
607+
box Node::new_branch(new_left,
608608
midpoint.clone().left))),
609-
~Node::new_branch(new_right, self.clone().rightmost_child));
609+
box Node::new_branch(new_right, self.clone().rightmost_child));
610610
return (new_branch, true);
611611
}
612612
}

src/libcollections/dlist.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<T> Deque<T> for DList<T> {
238238
///
239239
/// O(1)
240240
fn push_front(&mut self, elt: T) {
241-
self.push_front_node(~Node::new(elt))
241+
self.push_front_node(box Node::new(elt))
242242
}
243243

244244
/// 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> {
252252
///
253253
/// O(1)
254254
fn push_back(&mut self, elt: T) {
255-
self.push_back_node(~Node::new(elt))
255+
self.push_back_node(box Node::new(elt))
256256
}
257257

258258
/// Remove the last element and return it, or None if the list is empty
@@ -555,7 +555,7 @@ impl<'a, A> MutItems<'a, A> {
555555
impl<'a, A> ListInsertion<A> for MutItems<'a, A> {
556556
#[inline]
557557
fn insert_next(&mut self, elt: A) {
558-
self.insert_next_node(~Node::new(elt))
558+
self.insert_next_node(box Node::new(elt))
559559
}
560560

561561
#[inline]
@@ -675,19 +675,19 @@ mod tests {
675675
assert_eq!(m.pop_front(), None);
676676
assert_eq!(m.pop_back(), None);
677677
assert_eq!(m.pop_front(), None);
678-
m.push_front(~1);
678+
m.push_front(box 1);
679679
assert_eq!(m.pop_front(), Some(~1));
680-
m.push_back(~2);
681-
m.push_back(~3);
680+
m.push_back(box 2);
681+
m.push_back(box 3);
682682
assert_eq!(m.len(), 2);
683683
assert_eq!(m.pop_front(), Some(~2));
684684
assert_eq!(m.pop_front(), Some(~3));
685685
assert_eq!(m.len(), 0);
686686
assert_eq!(m.pop_front(), None);
687-
m.push_back(~1);
688-
m.push_back(~3);
689-
m.push_back(~5);
690-
m.push_back(~7);
687+
m.push_back(box 1);
688+
m.push_back(box 3);
689+
m.push_back(box 5);
690+
m.push_back(box 7);
691691
assert_eq!(m.pop_front(), Some(~1));
692692

693693
let mut n = DList::new();

src/libcollections/lru_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
9393
let cache = LruCache {
9494
map: HashMap::new(),
9595
max_size: capacity,
96-
head: unsafe{ cast::transmute(~mem::uninit::<LruEntry<K, V>>()) },
96+
head: unsafe{ cast::transmute(box mem::uninit::<LruEntry<K, V>>()) },
9797
};
9898
unsafe {
9999
(*cache.head).next = cache.head;
@@ -111,7 +111,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
111111
(node_ptr, None)
112112
}
113113
None => {
114-
let mut node = ~LruEntry::new(k, v);
114+
let mut node = box LruEntry::new(k, v);
115115
let node_ptr: *mut LruEntry<K, V> = &mut *node;
116116
(node_ptr, Some(node))
117117
}

src/libcollections/priority_queue.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,19 @@ mod tests {
273273
let mut heap = PriorityQueue::from_vec(vec!(~2, ~4, ~9));
274274
assert_eq!(heap.len(), 3);
275275
assert!(*heap.top() == ~9);
276-
heap.push(~11);
276+
heap.push(box 11);
277277
assert_eq!(heap.len(), 4);
278278
assert!(*heap.top() == ~11);
279-
heap.push(~5);
279+
heap.push(box 5);
280280
assert_eq!(heap.len(), 5);
281281
assert!(*heap.top() == ~11);
282-
heap.push(~27);
282+
heap.push(box 27);
283283
assert_eq!(heap.len(), 6);
284284
assert!(*heap.top() == ~27);
285-
heap.push(~3);
285+
heap.push(box 3);
286286
assert_eq!(heap.len(), 7);
287287
assert!(*heap.top() == ~27);
288-
heap.push(~103);
288+
heap.push(box 103);
289289
assert_eq!(heap.len(), 8);
290290
assert!(*heap.top() == ~103);
291291
}

src/libcollections/smallintmap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ mod test_map {
459459
#[test]
460460
fn test_move_iter() {
461461
let mut m = SmallIntMap::new();
462-
m.insert(1, ~2);
462+
m.insert(1, box 2);
463463
let mut called = false;
464464
for (k, v) in m.move_iter() {
465465
assert!(!called);
@@ -468,7 +468,7 @@ mod test_map {
468468
assert_eq!(v, ~2);
469469
}
470470
assert!(called);
471-
m.insert(2, ~1);
471+
m.insert(2, box 1);
472472
}
473473
}
474474

src/libcollections/treemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ fn insert<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
834834
}
835835
}
836836
None => {
837-
*node = Some(~TreeNode::new(key, value));
837+
*node = Some(box TreeNode::new(key, value));
838838
None
839839
}
840840
}

src/libcollections/trie.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T,
448448
// have to move out of `child`.
449449
match mem::replace(child, Nothing) {
450450
External(stored_key, stored_value) => {
451-
let mut new = ~TrieNode::new();
451+
let mut new = box TrieNode::new();
452452
insert(&mut new.count,
453453
&mut new.children[chunk(stored_key, idx)],
454454
stored_key, stored_value, idx + 1);

src/libgreen/basic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::unstable::sync::Exclusive;
2323

2424
/// This is the only exported function from this module.
2525
pub fn event_loop() -> ~EventLoop:Send {
26-
~BasicLoop::new() as ~EventLoop:Send
26+
box BasicLoop::new() as ~EventLoop:Send
2727
}
2828

2929
struct BasicLoop {
@@ -143,7 +143,7 @@ impl EventLoop for BasicLoop {
143143
fn pausable_idle_callback(&mut self, cb: ~Callback:Send)
144144
-> ~PausableIdleCallback:Send
145145
{
146-
let callback = ~BasicPausable::new(self, cb);
146+
let callback = box BasicPausable::new(self, cb);
147147
rtassert!(self.idle.is_none());
148148
unsafe {
149149
let cb_ptr: &*mut BasicPausable = cast::transmute(&callback);
@@ -156,7 +156,7 @@ impl EventLoop for BasicLoop {
156156
let id = self.next_remote;
157157
self.next_remote += 1;
158158
self.remotes.push((id, f));
159-
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback:Send
159+
box BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback:Send
160160
}
161161

162162
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> { None }

src/libgreen/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct Registers {
152152

153153
#[cfg(target_arch = "x86")]
154154
fn new_regs() -> ~Registers {
155-
~Registers {
155+
box Registers {
156156
eax: 0, ebx: 0, ecx: 0, edx: 0,
157157
ebp: 0, esi: 0, edi: 0, esp: 0,
158158
cs: 0, ds: 0, ss: 0, es: 0, fs: 0, gs: 0,
@@ -190,9 +190,9 @@ type Registers = [uint, ..34];
190190
type Registers = [uint, ..22];
191191

192192
#[cfg(windows, target_arch = "x86_64")]
193-
fn new_regs() -> ~Registers { ~([0, .. 34]) }
193+
fn new_regs() -> ~Registers { box [0, .. 34] }
194194
#[cfg(not(windows), target_arch = "x86_64")]
195-
fn new_regs() -> ~Registers { ~([0, .. 22]) }
195+
fn new_regs() -> ~Registers { box {let v = [0, .. 22]; v} }
196196

197197
#[cfg(target_arch = "x86_64")]
198198
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,
241241
type Registers = [uint, ..32];
242242

243243
#[cfg(target_arch = "arm")]
244-
fn new_regs() -> ~Registers { ~([0, .. 32]) }
244+
fn new_regs() -> ~Registers { box {[0, .. 32]} }
245245

246246
#[cfg(target_arch = "arm")]
247247
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,
270270
type Registers = [uint, ..32];
271271

272272
#[cfg(target_arch = "mips")]
273-
fn new_regs() -> ~Registers { ~([0, .. 32]) }
273+
fn new_regs() -> ~Registers { box [0, .. 32] }
274274

275275
#[cfg(target_arch = "mips")]
276276
fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,

src/libgreen/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl SchedPool {
427427
for worker in workers.move_iter() {
428428
rtdebug!("inserting a regular scheduler");
429429

430-
let mut sched = ~Scheduler::new(pool.id,
430+
let mut sched = box Scheduler::new(pool.id,
431431
(pool.factory)(),
432432
worker,
433433
pool.stealers.clone(),
@@ -488,7 +488,7 @@ impl SchedPool {
488488
// Create the new scheduler, using the same sleeper list as all the
489489
// other schedulers as well as having a stealer handle to all other
490490
// schedulers.
491-
let mut sched = ~Scheduler::new(self.id,
491+
let mut sched = box Scheduler::new(self.id,
492492
(self.factory)(),
493493
worker,
494494
self.stealers.clone(),

src/libgreen/sched.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Scheduler {
183183
pub fn bootstrap(mut ~self) {
184184

185185
// Build an Idle callback.
186-
let cb = ~SchedRunner as ~Callback:Send;
186+
let cb = box SchedRunner as ~Callback:Send;
187187
self.idle_callback = Some(self.event_loop.pausable_idle_callback(cb));
188188

189189
// Create a task for the scheduler with an empty context.
@@ -869,7 +869,7 @@ impl Scheduler {
869869
}
870870

871871
pub fn make_handle(&mut self) -> SchedHandle {
872-
let remote = self.event_loop.remote_callback(~SchedRunner);
872+
let remote = self.event_loop.remote_callback(box SchedRunner);
873873

874874
return SchedHandle {
875875
remote: remote,
@@ -1140,7 +1140,7 @@ mod test {
11401140
let (_p, state) = TaskState::new();
11411141

11421142
// Our normal scheduler
1143-
let mut normal_sched = ~Scheduler::new(
1143+
let mut normal_sched = box Scheduler::new(
11441144
1,
11451145
basic::event_loop(),
11461146
normal_worker,
@@ -1152,7 +1152,7 @@ mod test {
11521152
let friend_handle = normal_sched.make_handle();
11531153

11541154
// Our special scheduler
1155-
let mut special_sched = ~Scheduler::new_special(
1155+
let mut special_sched = box Scheduler::new_special(
11561156
1,
11571157
basic::event_loop(),
11581158
special_worker,
@@ -1403,7 +1403,7 @@ mod test {
14031403

14041404
impl Drop for S {
14051405
fn drop(&mut self) {
1406-
let _foo = ~0;
1406+
let _foo = box 0;
14071407
}
14081408
}
14091409

src/libgreen/simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl Runtime for SimpleTask {
8282
}
8383

8484
pub fn task() -> ~Task {
85-
let mut task = ~Task::new();
86-
task.put_runtime(~SimpleTask {
85+
let mut task = box Task::new();
86+
task.put_runtime(box SimpleTask {
8787
lock: unsafe {NativeMutex::new()},
8888
awoken: false,
8989
});

src/libgreen/task.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ impl GreenTask {
159159
/// useful when creating scheduler tasks.
160160
pub fn new_typed(coroutine: Option<Coroutine>,
161161
task_type: TaskType) -> ~GreenTask {
162-
~GreenTask {
162+
box GreenTask {
163163
pool_id: 0,
164164
coroutine: coroutine,
165165
task_type: task_type,
166166
sched: None,
167167
handle: None,
168168
nasty_deschedule_lock: unsafe { NativeMutex::new() },
169-
task: Some(~Task::new()),
169+
task: Some(box Task::new()),
170170
}
171171
}
172172

src/liblog/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub fn log(level: u32, args: &fmt::Arguments) {
203203
// frob the slot while we're doing the logging. This will destroy any logger
204204
// set during logging.
205205
let mut logger = local_data::pop(local_logger).unwrap_or_else(|| {
206-
~DefaultLogger { handle: io::stderr() } as ~Logger:Send
206+
box DefaultLogger { handle: io::stderr() } as ~Logger:Send
207207
});
208208
logger.log(level, args);
209209
local_data::set(local_logger, logger);
@@ -286,7 +286,7 @@ fn init() {
286286
LOG_LEVEL = max_level;
287287

288288
assert!(DIRECTIVES.is_null());
289-
DIRECTIVES = cast::transmute(~directives);
289+
DIRECTIVES = cast::transmute(box directives);
290290

291291
// Schedule the cleanup for this global for when the runtime exits.
292292
rt::at_exit(proc() {

src/libnative/io/file_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl rtio::RtioPipe for FileDesc {
176176
self.inner_write(buf)
177177
}
178178
fn clone(&self) -> ~rtio::RtioPipe:Send {
179-
~FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
179+
box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
180180
}
181181
}
182182

src/libnative/io/file_win32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl rtio::RtioPipe for FileDesc {
207207
self.inner_write(buf)
208208
}
209209
fn clone(&self) -> ~rtio::RtioPipe:Send {
210-
~FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
210+
box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send
211211
}
212212
}
213213

0 commit comments

Comments
 (0)