diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 717993e78c1..bfc5da65214 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -50,7 +50,7 @@ pure fn capacity(&&v: @[const T]) -> uint { pure fn build_sized(size: uint, builder: fn(push: pure fn(+A))) -> @[A] { let mut vec = @[]; unsafe { unsafe::reserve(vec, size); } - builder(|+x| unsafe { unsafe::push(vec, x) }); + builder(|+x| unsafe { unsafe::push(vec, move x) }); return vec; } @@ -163,10 +163,10 @@ mod unsafe { let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); let fill = (**repr).fill; if (**repr).alloc > fill { - push_fast(v, initval); + push_fast(v, move initval); } else { - push_slow(v, initval); + push_slow(v, move initval); } } // This doesn't bother to make sure we have space. @@ -182,7 +182,7 @@ mod unsafe { unsafe fn push_slow(&v: @[const T], +initval: T) { reserve_at_least(v, v.len() + 1u); - push_fast(v, initval); + push_fast(v, move initval); } /** diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 5dfafb85bbd..c85557c6cd8 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -76,7 +76,7 @@ fn Port() -> Port { impl Port { fn chan() -> Chan { Chan(self) } - fn send(+v: T) { self.chan().send(v) } + fn send(+v: T) { self.chan().send(move v) } fn recv() -> T { recv(self) } fn peek() -> bool { peek(self) } @@ -85,7 +85,7 @@ impl Port { impl Chan { fn chan() -> Chan { self } - fn send(+v: T) { send(self, v) } + fn send(+v: T) { send(self, move v) } fn recv() -> T { recv_chan(self) } fn peek() -> bool { peek_chan(self) } @@ -103,17 +103,17 @@ struct PortPtr { do task::unkillable { // Once the port is detached it's guaranteed not to receive further // messages - let yield = 0u; + let yield = 0; let yieldp = ptr::addr_of(yield); rustrt::rust_port_begin_detach(self.po, yieldp); - if yield != 0u { + if yield != 0 { // Need to wait for the port to be detached task::yield(); } rustrt::rust_port_end_detach(self.po); // Drain the port so that all the still-enqueued items get dropped - while rustrt::rust_port_size(self.po) > 0u as size_t { + while rustrt::rust_port_size(self.po) > 0 as size_t { recv_::(self.po); } rustrt::del_port(self.po); @@ -179,7 +179,7 @@ fn send(ch: Chan, +data: T) { let Chan_(p) = ch; let data_ptr = ptr::addr_of(data) as *(); let res = rustrt::rust_port_id_send(p, data_ptr); - if res != 0u unsafe { + if res != 0 unsafe { // Data sent successfully unsafe::forget(data); } @@ -206,13 +206,13 @@ fn peek_chan(ch: comm::Chan) -> bool { /// Receive on a raw port pointer fn recv_(p: *rust_port) -> T { - let yield = 0u; + let yield = 0; let yieldp = ptr::addr_of(yield); let mut res; res = rusti::init::(); rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp); - if yield != 0u { + if yield != 0 { // Data isn't available yet, so res has not been initialized. task::yield(); } else { @@ -220,21 +220,21 @@ fn recv_(p: *rust_port) -> T { // this is a good place to yield task::yield(); } - return res; + move res } fn peek_(p: *rust_port) -> bool { // Yield here before we check to see if someone sent us a message - // FIXME #524, if the compilergenerates yields, we don't need this + // FIXME #524, if the compiler generates yields, we don't need this task::yield(); - rustrt::rust_port_size(p) != 0u as libc::size_t + rustrt::rust_port_size(p) != 0 as libc::size_t } /// Receive on one of two ports fn select2(p_a: Port, p_b: Port) -> Either { let ports = ~[(**p_a).po, (**p_b).po]; - let yield = 0u, yieldp = ptr::addr_of(yield); + let yield = 0, yieldp = ptr::addr_of(yield); let mut resport: *rust_port; resport = rusti::init::<*rust_port>(); @@ -243,7 +243,7 @@ fn select2(p_a: Port, p_b: Port) n_ports as size_t, yieldp); } - if yield != 0u { + if yield != 0 { // Wait for data task::yield(); } else { @@ -380,16 +380,16 @@ fn test_select2_rendezvous() { let ch_a = Chan(po_a); let ch_b = Chan(po_b); - for iter::repeat(10u) { + for iter::repeat(10) { do task::spawn { - for iter::repeat(10u) { task::yield() } + for iter::repeat(10) { task::yield() } send(ch_a, ~"a"); }; assert select2(po_a, po_b) == either::Left(~"a"); do task::spawn { - for iter::repeat(10u) { task::yield() } + for iter::repeat(10) { task::yield() } send(ch_b, ~"b"); }; @@ -404,7 +404,7 @@ fn test_select2_stress() { let ch_a = Chan(po_a); let ch_b = Chan(po_b); - let msgs = 100u; + let msgs = 100; let times = 4u; for iter::repeat(times) { @@ -490,7 +490,7 @@ fn test_listen() { #[test] #[ignore(cfg(windows))] fn test_port_detach_fail() { - for iter::repeat(100u) { + for iter::repeat(100) { do task::spawn_unlinked { let po = Port(); let ch = po.chan(); diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index a1973c1d6ef..a7acceb1fe3 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -80,7 +80,7 @@ impl DListNode { /// Creates a new dlist node with the given data. pure fn new_dlist_node(+data: T) -> DListNode { - DListNode(@{data: data, mut linked: false, + DListNode(@{data: move data, mut linked: false, mut prev: None, mut next: None}) } @@ -92,7 +92,7 @@ pure fn DList() -> DList { /// Creates a new dlist with a single element pure fn from_elem(+data: T) -> DList { let list = DList(); - unchecked { list.push(data); } + unchecked { list.push(move data); } list } @@ -115,7 +115,7 @@ fn concat(lists: DList>) -> DList { priv impl DList { pure fn new_link(-data: T) -> DListLink { - Some(DListNode(@{data: data, mut linked: true, + Some(DListNode(@{data: move data, mut linked: true, mut prev: None, mut next: None})) } pure fn assert_mine(nobe: DListNode) { @@ -442,7 +442,7 @@ impl DList { v[index] = data; } } - v + move v } } diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 41f88b72ca1..35424a38fd8 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -64,18 +64,18 @@ fn DVec() -> DVec { /// Creates a new dvec with a single element fn from_elem(+e: A) -> DVec { - DVec_({mut data: ~[mut e]}) + DVec_({mut data: ~[mut move e]}) } /// Creates a new dvec with the contents of a vector fn from_vec(+v: ~[mut A]) -> DVec { - DVec_({mut data: v}) + DVec_({mut data: move v}) } /// Consumes the vector and returns its contents fn unwrap(+d: DVec) -> ~[mut A] { let DVec_({data: v}) <- d; - return v; + move v } priv impl DVec { @@ -149,7 +149,7 @@ impl DVec { let mut v <- v; let result = vec::pop(v); self.give_back(v); - result + move result } } @@ -161,7 +161,7 @@ impl DVec { let data_ptr: *() = unsafe::reinterpret_cast(&data); if data_ptr.is_null() { fail ~"Recursive use of dvec"; } log(error, ~"a"); - self.data <- ~[mut t]; + self.data <- ~[mut move t]; vec::push_all_move(self.data, data); log(error, ~"b"); } @@ -170,16 +170,16 @@ impl DVec { /// Append a single item to the end of the list fn push(+t: A) { self.check_not_borrowed(); - vec::push(self.data, t); + vec::push(self.data, move t); } /// Remove and return the first element fn shift() -> A { do self.check_out |v| { - let mut v = vec::from_mut(v); + let mut v = vec::from_mut(move v); let result = vec::shift(v); - self.give_back(vec::to_mut(v)); - result + self.give_back(vec::to_mut(move v)); + move result } } @@ -196,7 +196,7 @@ impl DVec { do self.check_out |v| { let result = op(v); self.give_back(v); - result + move result } } @@ -205,7 +205,7 @@ impl DVec { do self.check_out |v| { let result = op(v); self.give_back(v); - result + move result } } } @@ -231,7 +231,7 @@ impl DVec { vec::push(v, ts[i]); i += 1u; } - v + move v } } @@ -270,7 +270,7 @@ impl DVec { do self.check_out |v| { let w = vec::from_mut(copy v); self.give_back(v); - w + move w } } } @@ -297,7 +297,7 @@ impl DVec { do self.swap |v| { let mut v <- v; vec::grow_set(v, idx, initval, val); - v + move v } } @@ -317,13 +317,13 @@ impl DVec { /// Iterates over the elements in reverse order #[inline(always)] fn reach(f: fn(A) -> bool) { - do self.swap |v| { vec::reach(v, f); v } + do self.swap |v| { vec::reach(v, f); move v } } /// Iterates over the elements and indices in reverse order #[inline(always)] fn reachi(f: fn(uint, A) -> bool) { - do self.swap |v| { vec::reachi(v, f); v } + do self.swap |v| { vec::reachi(v, f); move v } } } diff --git a/src/libcore/either.rs b/src/libcore/either.rs index bd68fab3b8e..b97fd244940 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -39,7 +39,7 @@ fn lefts(eithers: &[Either]) -> ~[T] { _ => { /* fallthrough */ } } } - return result; + move result } fn rights(eithers: &[Either]) -> ~[U] { @@ -52,7 +52,7 @@ fn rights(eithers: &[Either]) -> ~[U] { _ => { /* fallthrough */ } } } - return result; + move result } fn partition(eithers: &[Either]) @@ -72,7 +72,7 @@ fn partition(eithers: &[Either]) Right(r) => vec::push(rights, r) } } - return {lefts: lefts, rights: rights}; + return {lefts: move lefts, rights: move rights}; } pure fn flip(eith: &Either) -> Either { @@ -114,7 +114,7 @@ pure fn unwrap_left(+eith: Either) -> T { //! Retrieves the value in the left branch. Fails if the either is Right. match move eith { - Left(move x) => x, Right(_) => fail ~"either::unwrap_left Right" + Left(move x) => move x, Right(_) => fail ~"either::unwrap_left Right" } } @@ -122,7 +122,7 @@ pure fn unwrap_right(+eith: Either) -> U { //! Retrieves the value in the right branch. Fails if the either is Left. match move eith { - Right(move x) => x, Left(_) => fail ~"either::unwrap_right Left" + Right(move x) => move x, Left(_) => fail ~"either::unwrap_right Left" } } diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index ef792ef690e..9fdfd7b102e 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -201,7 +201,7 @@ fn SipState(key0: u64, key1: u64) -> SipState { mut ntail : 0u, }; (&state).reset(); - return state; + move state } @@ -368,7 +368,7 @@ impl &SipState : Streaming { let r = self.result_bytes(); let mut s = ~""; for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); } - return s; + move s } #[inline(always)] diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index d9e5f3a0aee..55a13fab8e4 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -16,7 +16,7 @@ impl IMPL_T: iter::ExtendedIter { pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) } pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) } pure fn foldl(+b0: B, blk: fn(B, A) -> B) -> B { - iter::foldl(self, b0, blk) + iter::foldl(self, move b0, blk) } } diff --git a/src/libcore/iter-trait/dvec.rs b/src/libcore/iter-trait/dvec.rs index c50bd142725..854e75d2838 100644 --- a/src/libcore/iter-trait/dvec.rs +++ b/src/libcore/iter-trait/dvec.rs @@ -7,7 +7,7 @@ type IMPL_T = dvec::DVec; * Attempts to access this dvec during iteration will fail. */ pure fn EACH(self: IMPL_T, f: fn(A) -> bool) { - unsafe { self.swap(|v| { vec::each(v, f); v }) } + unsafe { self.swap(|v| { vec::each(v, f); move v }) } } pure fn SIZE_HINT(self: IMPL_T) -> Option { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 30bd66bf9f8..e9d6784136f 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -117,7 +117,7 @@ pure fn foldl>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { for self.each |a| { b = blk(b, a); } - return b; + move b } pure fn to_vec>(self: IA) -> ~[A] { diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 980f1899566..833a4cd8b1a 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -74,7 +74,7 @@ pure fn map_consume(+opt: Option, f: fn(+T) -> U) -> Option { * As `map`, but consumes the option and gives `f` ownership to avoid * copying. */ - if opt.is_some() { Some(f(option::unwrap(opt))) } else { None } + if opt.is_some() { Some(f(option::unwrap(move opt))) } else { None } } pure fn chain(opt: Option, f: fn(T) -> Option) -> Option { @@ -101,8 +101,8 @@ pure fn or(+opta: Option, +optb: Option) -> Option { * Returns the leftmost some() value, or none if both are none. */ match opta { - Some(_) => opta, - _ => optb + Some(_) => move opta, + _ => move optb } } @@ -112,7 +112,7 @@ pure fn while_some(+x: Option, blk: fn(+T) -> Option) { let mut opt <- x; while opt.is_some() { - opt = blk(unwrap(opt)); + opt = blk(unwrap(move opt)); } } @@ -137,7 +137,7 @@ pure fn get_default(opt: Option, def: T) -> T { pure fn map_default(opt: Option, +def: U, f: fn(T) -> U) -> U { //! Applies a function to the contained value or returns a default - match opt { None => def, Some(t) => f(t) } + match opt { None => move def, Some(t) => f(t) } } // This should replace map_default. @@ -145,7 +145,7 @@ pure fn map_default_ref(opt: &Option, +def: U, f: fn(x: &T) -> U) -> U { //! Applies a function to the contained value or returns a default - match *opt { None => def, Some(ref t) => f(t) } + match *opt { None => move def, Some(ref t) => f(t) } } // This should change to by-copy mode; use iter_ref below for by reference @@ -169,7 +169,7 @@ pure fn unwrap(+opt: Option) -> T { * of option types without copying them. */ match move opt { - Some(move x) => x, + Some(move x) => move x, None => fail ~"option::unwrap none" } } @@ -184,7 +184,7 @@ fn swap_unwrap(opt: &mut Option) -> T { pure fn unwrap_expect(+opt: Option, reason: &str) -> T { //! As unwrap, but with a specified failure message. if opt.is_none() { fail reason.to_unique(); } - unwrap(opt) + unwrap(move opt) } // Some of these should change to be &Option, some should not. See below. @@ -196,7 +196,7 @@ impl Option { pure fn chain(f: fn(T) -> Option) -> Option { chain(self, f) } /// Applies a function to the contained value or returns a default pure fn map_default(+def: U, f: fn(T) -> U) -> U - { map_default(self, def, f) } + { map_default(self, move def, f) } /// Performs an operation on the contained value or does nothing pure fn iter(f: fn(T)) { iter(self, f) } /// Returns true if the option equals `none` @@ -217,7 +217,7 @@ impl &Option { } /// Applies a function to the contained value or returns a default pure fn map_default_ref(+def: U, f: fn(x: &T) -> U) -> U - { map_default_ref(self, def, f) } + { map_default_ref(self, move def, f) } /// Performs an operation on the contained value by reference pure fn iter_ref(f: fn(x: &T)) { iter_ref(self, f) } /// Maps a `some` value from one type to another by reference diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 7f3f35acc90..7330d3520f6 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -277,7 +277,7 @@ fn map_vec( Err(u) => return Err(u) } } - return Ok(vs); + return Ok(move vs); } fn map_opt( @@ -316,7 +316,7 @@ fn map_vec2(ss: &[S], ts: &[T], } i += 1u; } - return Ok(vs); + return Ok(move vs); } /** @@ -343,7 +343,7 @@ fn iter_vec2(ss: &[S], ts: &[T], /// Unwraps a result, assuming it is an `ok(T)` fn unwrap(+res: Result) -> T { match move res { - Ok(move t) => t, + Ok(move t) => move t, Err(_) => fail ~"unwrap called on an err result" } } @@ -351,7 +351,7 @@ fn unwrap(+res: Result) -> T { /// Unwraps a result, assuming it is an `err(U)` fn unwrap_err(+res: Result) -> U { match move res { - Err(move u) => u, + Err(move u) => move u, Ok(_) => fail ~"unwrap called on an ok result" } } diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index a292d011644..182a592dad2 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -152,7 +152,7 @@ mod linear { for uint::range(0, old_capacity) |i| { let mut bucket = None; bucket <-> old_buckets[i]; - self.insert_opt_bucket(bucket); + self.insert_opt_bucket(move bucket); } } @@ -161,7 +161,7 @@ mod linear { Some(Bucket {hash: move hash, key: move key, value: move value}) => { - self.insert_internal(hash, key, value); + self.insert_internal(hash, move key, move value); } None => {} } @@ -213,7 +213,7 @@ mod linear { } let hash = k.hash_keyed(self.k0, self.k1) as uint; - self.insert_internal(hash, k, v) + self.insert_internal(hash, move k, move v) } fn remove(&mut self, k: &K) -> bool { @@ -247,7 +247,7 @@ mod linear { while self.buckets[idx].is_some() { let mut bucket = None; bucket <-> self.buckets[idx]; - self.insert_opt_bucket(bucket); + self.insert_opt_bucket(move bucket); idx = self.next_bucket(idx, len_buckets); } self.size -= 1; diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 76d684a16cd..21a29a6b07d 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -72,7 +72,7 @@ impl ~[A]: ToStr { str::push_str(acc, elt.to_str()); } str::push_char(acc, ']'); - acc + move acc } } diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index 4114adef8f0..2672c505779 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -55,13 +55,13 @@ impl (&[A], &[B]): ExtendedTupleOps { impl (~[A], ~[B]): ExtendedTupleOps { fn zip() -> ~[(A, B)] { - // XXX: Bad copy + // FIXME #2543: Bad copy let (a, b) = copy self; - vec::zip(a, b) + vec::zip(move a, move b) } fn map(f: fn(A, B) -> C) -> ~[C] { - // XXX: Bad copy + // FIXME #2543: Bad copy let (a, b) = copy self; vec::map2(a, b, f) } diff --git a/src/libcore/util.rs b/src/libcore/util.rs index e2128693ace..cc3d6dded6f 100644 --- a/src/libcore/util.rs +++ b/src/libcore/util.rs @@ -9,7 +9,7 @@ use cmp::Eq; */ /// The identity function. -pure fn id(+x: T) -> T { x } +pure fn id(+x: T) -> T { move x } /// Ignores a value. pure fn ignore(+_x: T) { } @@ -47,9 +47,9 @@ fn swap(x: &mut T, y: &mut T) { */ #[inline(always)] fn replace(dest: &mut T, +src: T) -> T { - let mut tmp = src; + let mut tmp <- src; swap(dest, &mut tmp); - tmp + move tmp } /// A non-copyable dummy type.