Skip to content

Commit e666fe8

Browse files
committed
Make more moves explicit in libcore
1 parent 1ff268e commit e666fe8

File tree

15 files changed

+77
-77
lines changed

15 files changed

+77
-77
lines changed

src/libcore/at_vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pure fn capacity<T>(&&v: @[const T]) -> uint {
5050
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> @[A] {
5151
let mut vec = @[];
5252
unsafe { unsafe::reserve(vec, size); }
53-
builder(|+x| unsafe { unsafe::push(vec, x) });
53+
builder(|+x| unsafe { unsafe::push(vec, move x) });
5454
return vec;
5555
}
5656

@@ -163,10 +163,10 @@ mod unsafe {
163163
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
164164
let fill = (**repr).fill;
165165
if (**repr).alloc > fill {
166-
push_fast(v, initval);
166+
push_fast(v, move initval);
167167
}
168168
else {
169-
push_slow(v, initval);
169+
push_slow(v, move initval);
170170
}
171171
}
172172
// This doesn't bother to make sure we have space.
@@ -182,7 +182,7 @@ mod unsafe {
182182

183183
unsafe fn push_slow<T>(&v: @[const T], +initval: T) {
184184
reserve_at_least(v, v.len() + 1u);
185-
push_fast(v, initval);
185+
push_fast(v, move initval);
186186
}
187187

188188
/**

src/libcore/comm.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn Port<T: Send>() -> Port<T> {
7676
impl<T: Send> Port<T> {
7777

7878
fn chan() -> Chan<T> { Chan(self) }
79-
fn send(+v: T) { self.chan().send(v) }
79+
fn send(+v: T) { self.chan().send(move v) }
8080
fn recv() -> T { recv(self) }
8181
fn peek() -> bool { peek(self) }
8282

@@ -85,7 +85,7 @@ impl<T: Send> Port<T> {
8585
impl<T: Send> Chan<T> {
8686

8787
fn chan() -> Chan<T> { self }
88-
fn send(+v: T) { send(self, v) }
88+
fn send(+v: T) { send(self, move v) }
8989
fn recv() -> T { recv_chan(self) }
9090
fn peek() -> bool { peek_chan(self) }
9191

@@ -103,17 +103,17 @@ struct PortPtr<T:Send> {
103103
do task::unkillable {
104104
// Once the port is detached it's guaranteed not to receive further
105105
// messages
106-
let yield = 0u;
106+
let yield = 0;
107107
let yieldp = ptr::addr_of(yield);
108108
rustrt::rust_port_begin_detach(self.po, yieldp);
109-
if yield != 0u {
109+
if yield != 0 {
110110
// Need to wait for the port to be detached
111111
task::yield();
112112
}
113113
rustrt::rust_port_end_detach(self.po);
114114

115115
// Drain the port so that all the still-enqueued items get dropped
116-
while rustrt::rust_port_size(self.po) > 0u as size_t {
116+
while rustrt::rust_port_size(self.po) > 0 as size_t {
117117
recv_::<T>(self.po);
118118
}
119119
rustrt::del_port(self.po);
@@ -179,7 +179,7 @@ fn send<T: Send>(ch: Chan<T>, +data: T) {
179179
let Chan_(p) = ch;
180180
let data_ptr = ptr::addr_of(data) as *();
181181
let res = rustrt::rust_port_id_send(p, data_ptr);
182-
if res != 0u unsafe {
182+
if res != 0 unsafe {
183183
// Data sent successfully
184184
unsafe::forget(data);
185185
}
@@ -206,35 +206,35 @@ fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
206206

207207
/// Receive on a raw port pointer
208208
fn recv_<T: Send>(p: *rust_port) -> T {
209-
let yield = 0u;
209+
let yield = 0;
210210
let yieldp = ptr::addr_of(yield);
211211
let mut res;
212212
res = rusti::init::<T>();
213213
rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp);
214214

215-
if yield != 0u {
215+
if yield != 0 {
216216
// Data isn't available yet, so res has not been initialized.
217217
task::yield();
218218
} else {
219219
// In the absence of compiler-generated preemption points
220220
// this is a good place to yield
221221
task::yield();
222222
}
223-
return res;
223+
move res
224224
}
225225

226226
fn peek_(p: *rust_port) -> bool {
227227
// Yield here before we check to see if someone sent us a message
228-
// FIXME #524, if the compilergenerates yields, we don't need this
228+
// FIXME #524, if the compiler generates yields, we don't need this
229229
task::yield();
230-
rustrt::rust_port_size(p) != 0u as libc::size_t
230+
rustrt::rust_port_size(p) != 0 as libc::size_t
231231
}
232232

233233
/// Receive on one of two ports
234234
fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
235235
-> Either<A, B> {
236236
let ports = ~[(**p_a).po, (**p_b).po];
237-
let yield = 0u, yieldp = ptr::addr_of(yield);
237+
let yield = 0, yieldp = ptr::addr_of(yield);
238238

239239
let mut resport: *rust_port;
240240
resport = rusti::init::<*rust_port>();
@@ -243,7 +243,7 @@ fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
243243
n_ports as size_t, yieldp);
244244
}
245245

246-
if yield != 0u {
246+
if yield != 0 {
247247
// Wait for data
248248
task::yield();
249249
} else {
@@ -380,16 +380,16 @@ fn test_select2_rendezvous() {
380380
let ch_a = Chan(po_a);
381381
let ch_b = Chan(po_b);
382382
383-
for iter::repeat(10u) {
383+
for iter::repeat(10) {
384384
do task::spawn {
385-
for iter::repeat(10u) { task::yield() }
385+
for iter::repeat(10) { task::yield() }
386386
send(ch_a, ~"a");
387387
};
388388

389389
assert select2(po_a, po_b) == either::Left(~"a");
390390

391391
do task::spawn {
392-
for iter::repeat(10u) { task::yield() }
392+
for iter::repeat(10) { task::yield() }
393393
send(ch_b, ~"b");
394394
};
395395
@@ -404,7 +404,7 @@ fn test_select2_stress() {
404404
let ch_a = Chan(po_a);
405405
let ch_b = Chan(po_b);
406406
407-
let msgs = 100u;
407+
let msgs = 100;
408408
let times = 4u;
409409
410410
for iter::repeat(times) {
@@ -490,7 +490,7 @@ fn test_listen() {
490490
#[test]
491491
#[ignore(cfg(windows))]
492492
fn test_port_detach_fail() {
493-
for iter::repeat(100u) {
493+
for iter::repeat(100) {
494494
do task::spawn_unlinked {
495495
let po = Port();
496496
let ch = po.chan();

src/libcore/dlist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<T> DListNode<T> {
8080

8181
/// Creates a new dlist node with the given data.
8282
pure fn new_dlist_node<T>(+data: T) -> DListNode<T> {
83-
DListNode(@{data: data, mut linked: false,
83+
DListNode(@{data: move data, mut linked: false,
8484
mut prev: None, mut next: None})
8585
}
8686

@@ -92,7 +92,7 @@ pure fn DList<T>() -> DList<T> {
9292
/// Creates a new dlist with a single element
9393
pure fn from_elem<T>(+data: T) -> DList<T> {
9494
let list = DList();
95-
unchecked { list.push(data); }
95+
unchecked { list.push(move data); }
9696
list
9797
}
9898

@@ -115,7 +115,7 @@ fn concat<T>(lists: DList<DList<T>>) -> DList<T> {
115115

116116
priv impl<T> DList<T> {
117117
pure fn new_link(-data: T) -> DListLink<T> {
118-
Some(DListNode(@{data: data, mut linked: true,
118+
Some(DListNode(@{data: move data, mut linked: true,
119119
mut prev: None, mut next: None}))
120120
}
121121
pure fn assert_mine(nobe: DListNode<T>) {
@@ -442,7 +442,7 @@ impl<T: Copy> DList<T> {
442442
v[index] = data;
443443
}
444444
}
445-
v
445+
move v
446446
}
447447
}
448448

src/libcore/dvec.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ fn DVec<A>() -> DVec<A> {
6464

6565
/// Creates a new dvec with a single element
6666
fn from_elem<A>(+e: A) -> DVec<A> {
67-
DVec_({mut data: ~[mut e]})
67+
DVec_({mut data: ~[mut move e]})
6868
}
6969

7070
/// Creates a new dvec with the contents of a vector
7171
fn from_vec<A>(+v: ~[mut A]) -> DVec<A> {
72-
DVec_({mut data: v})
72+
DVec_({mut data: move v})
7373
}
7474

7575
/// Consumes the vector and returns its contents
7676
fn unwrap<A>(+d: DVec<A>) -> ~[mut A] {
7777
let DVec_({data: v}) <- d;
78-
return v;
78+
move v
7979
}
8080

8181
priv impl<A> DVec<A> {
@@ -149,7 +149,7 @@ impl<A> DVec<A> {
149149
let mut v <- v;
150150
let result = vec::pop(v);
151151
self.give_back(v);
152-
result
152+
move result
153153
}
154154
}
155155

@@ -161,7 +161,7 @@ impl<A> DVec<A> {
161161
let data_ptr: *() = unsafe::reinterpret_cast(&data);
162162
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
163163
log(error, ~"a");
164-
self.data <- ~[mut t];
164+
self.data <- ~[mut move t];
165165
vec::push_all_move(self.data, data);
166166
log(error, ~"b");
167167
}
@@ -170,16 +170,16 @@ impl<A> DVec<A> {
170170
/// Append a single item to the end of the list
171171
fn push(+t: A) {
172172
self.check_not_borrowed();
173-
vec::push(self.data, t);
173+
vec::push(self.data, move t);
174174
}
175175
176176
/// Remove and return the first element
177177
fn shift() -> A {
178178
do self.check_out |v| {
179-
let mut v = vec::from_mut(v);
179+
let mut v = vec::from_mut(move v);
180180
let result = vec::shift(v);
181-
self.give_back(vec::to_mut(v));
182-
result
181+
self.give_back(vec::to_mut(move v));
182+
move result
183183
}
184184
}
185185
@@ -196,7 +196,7 @@ impl<A> DVec<A> {
196196
do self.check_out |v| {
197197
let result = op(v);
198198
self.give_back(v);
199-
result
199+
move result
200200
}
201201
}
202202
@@ -205,7 +205,7 @@ impl<A> DVec<A> {
205205
do self.check_out |v| {
206206
let result = op(v);
207207
self.give_back(v);
208-
result
208+
move result
209209
}
210210
}
211211
}
@@ -231,7 +231,7 @@ impl<A: Copy> DVec<A> {
231231
vec::push(v, ts[i]);
232232
i += 1u;
233233
}
234-
v
234+
move v
235235
}
236236
}
237237
@@ -270,7 +270,7 @@ impl<A: Copy> DVec<A> {
270270
do self.check_out |v| {
271271
let w = vec::from_mut(copy v);
272272
self.give_back(v);
273-
w
273+
move w
274274
}
275275
}
276276
}
@@ -297,7 +297,7 @@ impl<A: Copy> DVec<A> {
297297
do self.swap |v| {
298298
let mut v <- v;
299299
vec::grow_set(v, idx, initval, val);
300-
v
300+
move v
301301
}
302302
}
303303
@@ -317,13 +317,13 @@ impl<A: Copy> DVec<A> {
317317
/// Iterates over the elements in reverse order
318318
#[inline(always)]
319319
fn reach(f: fn(A) -> bool) {
320-
do self.swap |v| { vec::reach(v, f); v }
320+
do self.swap |v| { vec::reach(v, f); move v }
321321
}
322322

323323
/// Iterates over the elements and indices in reverse order
324324
#[inline(always)]
325325
fn reachi(f: fn(uint, A) -> bool) {
326-
do self.swap |v| { vec::reachi(v, f); v }
326+
do self.swap |v| { vec::reachi(v, f); move v }
327327
}
328328
}
329329

src/libcore/either.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
3939
_ => { /* fallthrough */ }
4040
}
4141
}
42-
return result;
42+
move result
4343
}
4444

4545
fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
@@ -52,7 +52,7 @@ fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
5252
_ => { /* fallthrough */ }
5353
}
5454
}
55-
return result;
55+
move result
5656
}
5757

5858
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
@@ -72,7 +72,7 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
7272
Right(r) => vec::push(rights, r)
7373
}
7474
}
75-
return {lefts: lefts, rights: rights};
75+
return {lefts: move lefts, rights: move rights};
7676
}
7777

7878
pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
@@ -114,15 +114,15 @@ pure fn unwrap_left<T,U>(+eith: Either<T,U>) -> T {
114114
//! Retrieves the value in the left branch. Fails if the either is Right.
115115
116116
match move eith {
117-
Left(move x) => x, Right(_) => fail ~"either::unwrap_left Right"
117+
Left(move x) => move x, Right(_) => fail ~"either::unwrap_left Right"
118118
}
119119
}
120120

121121
pure fn unwrap_right<T,U>(+eith: Either<T,U>) -> U {
122122
//! Retrieves the value in the right branch. Fails if the either is Left.
123123
124124
match move eith {
125-
Right(move x) => x, Left(_) => fail ~"either::unwrap_right Left"
125+
Right(move x) => move x, Left(_) => fail ~"either::unwrap_right Left"
126126
}
127127
}
128128

src/libcore/hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn SipState(key0: u64, key1: u64) -> SipState {
201201
mut ntail : 0u,
202202
};
203203
(&state).reset();
204-
return state;
204+
move state
205205
}
206206

207207

@@ -368,7 +368,7 @@ impl &SipState : Streaming {
368368
let r = self.result_bytes();
369369
let mut s = ~"";
370370
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
371-
return s;
371+
move s
372372
}
373373

374374
#[inline(always)]

src/libcore/iter-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
1616
pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
1717
pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
1818
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
19-
iter::foldl(self, b0, blk)
19+
iter::foldl(self, move b0, blk)
2020
}
2121
}
2222

0 commit comments

Comments
 (0)