Skip to content

Commit f2d9d0b

Browse files
committed
Make all remaining moves explicit in libcore
1 parent 93d3b8a commit f2d9d0b

File tree

9 files changed

+54
-54
lines changed

9 files changed

+54
-54
lines changed

src/libcore/extfmt.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,35 @@ mod ct {
8888
let lim = str::len(s);
8989
let mut buf = ~"";
9090
fn flush_buf(+buf: ~str, &pieces: ~[piece]) -> ~str {
91-
if str::len(buf) > 0u {
92-
let piece = piece_string(buf);
93-
vec::push(pieces, piece);
91+
if str::len(buf) > 0 {
92+
let piece = piece_string(move buf);
93+
vec::push(pieces, move piece);
9494
}
9595
return ~"";
9696
}
97-
let mut i = 0u;
97+
let mut i = 0;
9898
while i < lim {
9999
let size = str::utf8_char_width(s[i]);
100100
let curr = str::slice(s, i, i+size);
101101
if curr == ~"%" {
102-
i += 1u;
102+
i += 1;
103103
if i >= lim {
104104
error(~"unterminated conversion at end of string");
105105
}
106-
let curr2 = str::slice(s, i, i+1u);
106+
let curr2 = str::slice(s, i, i+1);
107107
if curr2 == ~"%" {
108108
buf += curr2;
109-
i += 1u;
109+
i += 1;
110110
} else {
111-
buf = flush_buf(buf, pieces);
111+
buf = flush_buf(move buf, pieces);
112112
let rs = parse_conversion(s, i, lim, error);
113113
vec::push(pieces, copy rs.piece);
114114
i = rs.next;
115115
}
116116
} else { buf += curr; i += size; }
117117
}
118-
flush_buf(buf, pieces);
119-
return pieces;
118+
flush_buf(move buf, pieces);
119+
move pieces
120120
}
121121
fn peek_num(s: ~str, i: uint, lim: uint) ->
122122
Option<{num: uint, next: uint}> {
@@ -173,7 +173,7 @@ mod ct {
173173
fn parse_flags(s: ~str, i: uint, lim: uint) ->
174174
{flags: ~[flag], next: uint} {
175175
let noflags: ~[flag] = ~[];
176-
if i >= lim { return {flags: noflags, next: i}; }
176+
if i >= lim { return {flags: move noflags, next: i}; }
177177
178178
fn more_(f: flag, s: ~str, i: uint, lim: uint) ->
179179
{flags: ~[flag], next: uint} {
@@ -376,7 +376,7 @@ mod rt {
376376
let diff = prec - len;
377377
let pad = str::from_chars(vec::from_elem(diff, '0'));
378378
pad + s
379-
} else { s }
379+
} else { move s }
380380
};
381381
}
382382
pure fn get_int_precision(cv: conv) -> uint {

src/libcore/flate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn deflate_buf(buf: &[const u8]) -> ~[u8] {
3131
let out = vec::unsafe::from_buf(res as *u8,
3232
outsz as uint);
3333
libc::free(res);
34-
out
34+
move out
3535
}
3636
}
3737
}
@@ -49,7 +49,7 @@ fn inflate_buf(buf: &[const u8]) -> ~[u8] {
4949
let out = vec::unsafe::from_buf(res as *u8,
5050
outsz as uint);
5151
libc::free(res);
52-
out
52+
move out
5353
}
5454
}
5555
}

src/libcore/io.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<T: Reader> T : ReaderUtil {
5858
let count = self.read(buf, len);
5959

6060
unsafe { vec::unsafe::set_len(buf, count); }
61-
vec::from_mut(buf)
61+
vec::from_mut(move buf)
6262
}
6363
fn read_line() -> ~str {
6464
let mut buf = ~[];
@@ -128,7 +128,7 @@ impl Reader {
128128
buf = vec::slice(buf, offset, vec::len(buf));
129129
}
130130
}
131-
chars
131+
move chars
132132
}
133133

134134
fn read_char() -> char {
@@ -180,7 +180,7 @@ impl Reader {
180180
fn read_whole_stream() -> ~[u8] {
181181
let mut buf: ~[u8] = ~[];
182182
while !self.eof() { vec::push_all(buf, self.read_bytes(2048u)); }
183-
buf
183+
move buf
184184
}
185185

186186
fn each_byte(it: fn(int) -> bool) {
@@ -688,7 +688,7 @@ impl MemBuffer: Writer {
688688
689689
self.pos += v_len;
690690
691-
buf
691+
move buf
692692
}
693693
}
694694
fn seek(offset: int, whence: SeekStyle) {

src/libcore/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mod global_env {
215215
assert vec::len(vs) == 2u;
216216
vec::push(pairs, (copy vs[0], copy vs[1]));
217217
}
218-
return pairs;
218+
move pairs
219219
}
220220

221221
#[cfg(unix)]

src/libcore/path.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl PosixPath : GenericPath {
9999
if s.len() == 0 {
100100
~"."
101101
} else {
102-
s
102+
move s
103103
}
104104
}
105105
}
@@ -139,7 +139,7 @@ impl PosixPath : GenericPath {
139139
let dpath = from_str::<PosixPath>(d);
140140
match self.filename() {
141141
Some(ref f) => dpath.push(*f),
142-
None => dpath
142+
None => move dpath
143143
}
144144
}
145145

@@ -197,8 +197,7 @@ impl PosixPath : GenericPath {
197197
}
198198

199199
pure fn push_many(cs: &[~str]) -> PosixPath {
200-
return PosixPath { components: self.components + cs,
201-
..self }
200+
PosixPath { components: (copy self.components) + copy cs, ..self }
202201
}
203202

204203
pure fn push(s: &str) -> PosixPath {
@@ -288,7 +287,7 @@ impl WindowsPath : GenericPath {
288287
if s.len() == 0 {
289288
~"."
290289
} else {
291-
s
290+
move s
292291
}
293292
}
294293
}
@@ -328,7 +327,7 @@ impl WindowsPath : GenericPath {
328327
let dpath = from_str::<WindowsPath>(d);
329328
match self.filename() {
330329
Some(ref f) => dpath.push(*f),
331-
None => dpath
330+
None => move dpath
332331
}
333332
}
334333

@@ -386,7 +385,7 @@ impl WindowsPath : GenericPath {
386385
}
387386

388387
pure fn push_many(cs: &[~str]) -> WindowsPath {
389-
return WindowsPath { components: self.components + cs,
388+
return WindowsPath { components: (copy self.components) + (copy cs),
390389
..self }
391390
}
392391

@@ -428,7 +427,7 @@ pure fn normalize(components: &[~str]) -> ~[~str] {
428427
}
429428
}
430429
}
431-
cs
430+
move cs
432431
}
433432
434433
mod posix {
@@ -525,7 +524,7 @@ mod windows {
525524
if s[i] == '\\' as u8 {
526525
let pre = s.slice(2, i);
527526
let rest = s.slice(i, s.len());
528-
return Some((pre, rest));
527+
return Some((move pre, move rest));
529528
}
530529
i += 1;
531530
}
@@ -543,7 +542,7 @@ mod windows {
543542
} else {
544543
s.slice(2, s.len())
545544
};
546-
return Some((s.slice(0,1), rest));
545+
return Some((s.slice(0,1), move rest));
547546
}
548547
None
549548
}

src/libcore/priv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ unsafe fn chan_from_global_ptr<T: Send>(
4646
// There's no global channel. We must make it
4747
4848
let (setup_po, setup_ch) = do task_fn().spawn_conversation
49-
|setup_po, setup_ch| {
49+
|move f, setup_po, setup_ch| {
5050
let po = comm::Port::<T>();
5151
let ch = comm::Chan(po);
5252
comm::send(setup_ch, ch);
5353
5454
// Wait to hear if we are the official instance of
5555
// this global task
5656
match comm::recv::<Msg>(setup_po) {
57-
Proceed => f(po),
57+
Proceed => f(move po),
5858
Abort => ()
5959
}
6060
};

src/libcore/rand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Rng {
154154
s = s + str::from_char(self.gen_char_from(charset));
155155
i += 1u;
156156
}
157-
s
157+
move s
158158
}
159159

160160
/// Return a random byte string of the specified length
@@ -220,14 +220,14 @@ impl Rng {
220220
vec::push(r, item.item);
221221
}
222222
}
223-
r
223+
move r
224224
}
225225

226226
/// Shuffle a vec
227227
fn shuffle<T:Copy>(values: &[T]) -> ~[T] {
228228
let mut m = vec::from_slice(values);
229229
self.shuffle_mut(m);
230-
return m;
230+
move m
231231
}
232232

233233
/// Shuffle a mutable vec in place

src/libcore/run.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ fn read_all(rd: io::Reader) -> ~str {
260260
let bytes = rd.read_bytes(4096u);
261261
buf += str::from_bytes(bytes);
262262
}
263-
return buf;
263+
move buf
264264
}
265265

266266
/**
@@ -306,11 +306,11 @@ fn program_output(prog: &str, args: &[~str]) ->
306306
let ch = comm::Chan(p);
307307
do task::spawn_sched(task::SingleThreaded) {
308308
let errput = readclose(pipe_err.in);
309-
comm::send(ch, (2, errput));
309+
comm::send(ch, (2, move errput));
310310
};
311311
do task::spawn_sched(task::SingleThreaded) {
312312
let output = readclose(pipe_out.in);
313-
comm::send(ch, (1, output));
313+
comm::send(ch, (1, move output));
314314
};
315315
let status = run::waitpid(pid);
316316
let mut errs = ~"";
@@ -332,7 +332,7 @@ fn program_output(prog: &str, args: &[~str]) ->
332332
};
333333
count -= 1;
334334
};
335-
return {status: status, out: outs, err: errs};
335+
return {status: status, out: move outs, err: move errs};
336336
}
337337

338338
fn writeclose(fd: c_int, s: &str) {
@@ -354,7 +354,7 @@ fn readclose(fd: c_int) -> ~str {
354354
buf += str::from_bytes(bytes);
355355
}
356356
os::fclose(file);
357-
return buf;
357+
move buf
358358
}
359359

360360
/// Waits for a process to exit and returns the exit code

src/libcore/unsafe.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ unsafe fn bump_box_refcount<T>(+t: @T) { forget(t); }
5353
unsafe fn transmute<L, G>(-thing: L) -> G {
5454
let newthing = reinterpret_cast(&thing);
5555
forget(thing);
56-
return newthing;
56+
move newthing
5757
}
5858

5959
/// Coerce an immutable reference to be mutable.
@@ -113,9 +113,9 @@ struct ArcDestruct<T> {
113113
unsafe::reinterpret_cast(&data.unwrapper);
114114
let (message, response) = option::swap_unwrap(p);
115115
// Send 'ready' and wait for a response.
116-
pipes::send_one(message, ());
116+
pipes::send_one(move message, ());
117117
// Unkillable wait. Message guaranteed to come.
118-
if pipes::recv_one(response) {
118+
if pipes::recv_one(move response) {
119119
// Other task got the data.
120120
unsafe::forget(data);
121121
} else {
@@ -147,13 +147,13 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
147147
// In case we get killed early, we need to tell the person who
148148
// tried to wake us whether they should hand-off the data to us.
149149
if task::failing() {
150-
pipes::send_one(response, false);
150+
pipes::send_one(move response, false);
151151
// Either this swap_unwrap or the one below (at "Got here")
152152
// ought to run.
153153
unsafe::forget(option::swap_unwrap(&mut self.ptr));
154154
} else {
155155
assert self.ptr.is_none();
156-
pipes::send_one(response, true);
156+
pipes::send_one(move response, true);
157157
}
158158
}
159159
}
@@ -162,7 +162,7 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
162162
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&rc.data);
163163
let (c1,p1) = pipes::oneshot(); // ()
164164
let (c2,p2) = pipes::oneshot(); // bool
165-
let server: UnwrapProto = ~mut Some((c1,p2));
165+
let server: UnwrapProto = ~mut Some((move c1,move p2));
166166
let serverp: libc::uintptr_t = unsafe::transmute(server);
167167
// Try to put our server end in the unwrapper slot.
168168
if rustrt::rust_compare_and_swap_ptr(&mut ptr.unwrapper, 0, serverp) {
@@ -180,8 +180,9 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
180180
} else {
181181
// The *next* person who sees the refcount hit 0 will wake us.
182182
let end_result =
183-
DeathThroes { ptr: Some(ptr), response: Some(c2) };
184-
let mut p1 = Some(p1); // argh
183+
DeathThroes { ptr: Some(move ptr),
184+
response: Some(move c2) };
185+
let mut p1 = Some(move p1); // argh
185186
do task::rekillable {
186187
pipes::recv_one(option::swap_unwrap(&mut p1));
187188
}
@@ -210,7 +211,7 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>)
210211
type SharedMutableState<T: Send> = ArcDestruct<T>;
211212
212213
unsafe fn shared_mutable_state<T: Send>(+data: T) -> SharedMutableState<T> {
213-
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(data) };
214+
let data = ~ArcData { count: 1, unwrapper: 0, data: Some(move data) };
214215
unsafe {
215216
let ptr = unsafe::transmute(data);
216217
ArcDestruct(ptr)
@@ -322,7 +323,7 @@ fn exclusive<T:Send >(+user_data: T) -> Exclusive<T> {
322323
let data = ExData {
323324
lock: LittleLock(), mut failed: false, mut data: user_data
324325
};
325-
Exclusive { x: unsafe { shared_mutable_state(data) } }
326+
Exclusive { x: unsafe { shared_mutable_state(move data) } }
326327
}
327328

328329
impl<T: Send> Exclusive<T> {
@@ -347,17 +348,17 @@ impl<T: Send> Exclusive<T> {
347348
rec.failed = true;
348349
let result = f(&mut rec.data);
349350
rec.failed = false;
350-
result
351+
move result
351352
}
352353
}
353354
}
354355
355356
// FIXME(#2585) make this a by-move method on the exclusive
356357
fn unwrap_exclusive<T: Send>(+arc: Exclusive<T>) -> T {
357-
let Exclusive { x: x } = arc;
358-
let inner = unsafe { unwrap_shared_mutable_state(x) };
359-
let ExData { data: data, _ } = inner;
360-
data
358+
let Exclusive { x: x } <- arc;
359+
let inner = unsafe { unwrap_shared_mutable_state(move x) };
360+
let ExData { data: data, _ } <- inner;
361+
move data
361362
}
362363
363364
/****************************************************************************

0 commit comments

Comments
 (0)