From eb48c296817be7529a1757ac8d4798112717eaa9 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 15 Jun 2013 20:26:59 -0400 Subject: [PATCH] Add copies to type params with Copy bound --- src/libextra/deque.rs | 36 +-- src/libextra/dlist.rs | 17 +- src/libextra/future.rs | 2 +- src/libextra/list.rs | 4 +- src/libextra/smallintmap.rs | 2 +- src/libextra/sort.rs | 18 +- src/librustc/metadata/encoder.rs | 2 +- src/librustc/middle/trans/debuginfo.rs | 4 +- src/librustc/middle/ty.rs | 6 +- src/librustc/middle/typeck/infer/lattice.rs | 65 +++--- src/librustc/middle/typeck/infer/mod.rs | 4 +- src/librustc/middle/typeck/infer/unify.rs | 42 ++-- src/libstd/at_vec.rs | 6 +- src/libstd/either.rs | 4 +- src/libstd/io.rs | 2 +- src/libstd/num/num.rs | 6 +- src/libstd/num/strconv.rs | 28 +-- src/libstd/old_iter.rs | 12 +- src/libstd/option.rs | 12 +- src/libstd/rand.rs | 6 +- src/libstd/tuple.rs | 6 +- src/libstd/vec.rs | 34 +-- src/libsyntax/ast_util.rs | 52 ++--- src/libsyntax/diagnostic.rs | 2 +- src/libsyntax/print/pprust.rs | 12 +- src/libsyntax/util/interner.rs | 6 +- src/libsyntax/visit.rs | 212 ++++++++++-------- src/test/auxiliary/cci_capture_clause.rs | 2 +- src/test/auxiliary/cci_nested_lib.rs | 2 +- src/test/bench/msgsend-pipes-shared.rs | 6 +- src/test/bench/msgsend-pipes.rs | 6 +- src/test/bench/msgsend-ring-pipes.rs | 6 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 8 +- .../compile-fail/infinite-instantiation.rs | 2 +- src/test/compile-fail/kindck-owned.rs | 5 +- src/test/run-pass/alignment-gep-tup-like-1.rs | 2 +- src/test/run-pass/alignment-gep-tup-like-2.rs | 2 +- src/test/run-pass/auto-encode.rs | 61 ++--- .../borrowck-move-from-unsafe-ptr-ok.rs | 21 -- src/test/run-pass/borrowed-ptr-pattern.rs | 2 +- src/test/run-pass/box-unbox.rs | 2 +- .../close-over-big-then-small-data.rs | 2 +- src/test/run-pass/expr-block-generic-box2.rs | 2 +- .../run-pass/expr-block-generic-unique2.rs | 2 +- src/test/run-pass/expr-block-generic.rs | 2 +- src/test/run-pass/expr-if-generic-box2.rs | 2 +- src/test/run-pass/expr-if-generic.rs | 2 +- src/test/run-pass/expr-match-generic-box2.rs | 2 +- src/test/run-pass/expr-match-generic.rs | 2 +- src/test/run-pass/generic-derived-type.rs | 3 +- src/test/run-pass/issue-2718.rs | 8 +- src/test/run-pass/ivec-add.rs | 4 +- .../run-pass/kindck-owned-trait-contains-1.rs | 2 +- src/test/run-pass/reflect-visit-data.rs | 4 +- src/test/run-pass/resource-generic.rs | 2 +- src/test/run-pass/static-method-test.rs | 2 +- 56 files changed, 380 insertions(+), 390 deletions(-) delete mode 100644 src/test/run-pass/borrowck-move-from-unsafe-ptr-ok.rs diff --git a/src/libextra/deque.rs b/src/libextra/deque.rs index 89e23a3a77f..c8bb984736a 100644 --- a/src/libextra/deque.rs +++ b/src/libextra/deque.rs @@ -264,31 +264,31 @@ mod tests { fn test_parameterized(a: T, b: T, c: T, d: T) { let mut deq = Deque::new(); assert_eq!(deq.len(), 0); - deq.add_front(a); - deq.add_front(b); - deq.add_back(c); + deq.add_front(copy a); + deq.add_front(copy b); + deq.add_back(copy c); assert_eq!(deq.len(), 3); - deq.add_back(d); + deq.add_back(copy d); assert_eq!(deq.len(), 4); - assert_eq!(*deq.peek_front(), b); - assert_eq!(*deq.peek_back(), d); - assert_eq!(deq.pop_front(), b); - assert_eq!(deq.pop_back(), d); - assert_eq!(deq.pop_back(), c); - assert_eq!(deq.pop_back(), a); + assert_eq!(copy *deq.peek_front(), copy b); + assert_eq!(copy *deq.peek_back(), copy d); + assert_eq!(deq.pop_front(), copy b); + assert_eq!(deq.pop_back(), copy d); + assert_eq!(deq.pop_back(), copy c); + assert_eq!(deq.pop_back(), copy a); assert_eq!(deq.len(), 0); - deq.add_back(c); + deq.add_back(copy c); assert_eq!(deq.len(), 1); - deq.add_front(b); + deq.add_front(copy b); assert_eq!(deq.len(), 2); - deq.add_back(d); + deq.add_back(copy d); assert_eq!(deq.len(), 3); - deq.add_front(a); + deq.add_front(copy a); assert_eq!(deq.len(), 4); - assert_eq!(*deq.get(0), a); - assert_eq!(*deq.get(1), b); - assert_eq!(*deq.get(2), c); - assert_eq!(*deq.get(3), d); + assert_eq!(copy *deq.get(0), copy a); + assert_eq!(copy *deq.get(1), copy b); + assert_eq!(copy *deq.get(2), copy c); + assert_eq!(copy *deq.get(3), copy d); } #[deriving(Eq)] diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index c3e2beb122f..a67b1738819 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -111,7 +111,8 @@ pub fn from_elem(data: T) -> @mut DList { /// Creates a new dlist from a vector of elements, maintaining the same order pub fn from_vec(vec: &[T]) -> @mut DList { do vec.iter().fold(DList()) |list,data| { - list.push(*data); // Iterating left-to-right -- add newly to the tail. + // Iterating left-to-right -- add newly to the tail. + list.push(copy *data); list } } @@ -460,35 +461,35 @@ impl DList { impl DList { /// Remove data from the head of the list. O(1). pub fn pop(@mut self) -> Option { - self.pop_n().map(|nobe| nobe.data) + self.pop_n().map(|nobe| copy nobe.data) } /// Remove data from the tail of the list. O(1). pub fn pop_tail(@mut self) -> Option { - self.pop_tail_n().map(|nobe| nobe.data) + self.pop_tail_n().map(|nobe| copy nobe.data) } /// Get data at the list's head. O(1). pub fn peek(@mut self) -> Option { - self.peek_n().map(|nobe| nobe.data) + self.peek_n().map(|nobe| copy nobe.data) } /// Get data at the list's tail. O(1). pub fn peek_tail(@mut self) -> Option { - self.peek_tail_n().map (|nobe| nobe.data) + self.peek_tail_n().map (|nobe| copy nobe.data) } /// Get data at the list's head, failing if empty. O(1). - pub fn head(@mut self) -> T { self.head_n().data } + pub fn head(@mut self) -> T { copy self.head_n().data } /// Get data at the list's tail, failing if empty. O(1). - pub fn tail(@mut self) -> T { self.tail_n().data } + pub fn tail(@mut self) -> T { copy self.tail_n().data } /// Get the elements of the list as a vector. O(n). pub fn to_vec(@mut self) -> ~[T] { let mut v = vec::with_capacity(self.size); for old_iter::eachi(&self) |index,data| { - v[index] = *data; + v[index] = copy *data; } v } diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 40cfeebd5dc..4652e1d6477 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -57,7 +57,7 @@ priv enum FutureState { impl Future { pub fn get(&mut self) -> A { //! Get the value of the future. - *(self.get_ref()) + copy *(self.get_ref()) } } diff --git a/src/libextra/list.rs b/src/libextra/list.rs index 68d9bb4e1ae..34c35e0d7fd 100644 --- a/src/libextra/list.rs +++ b/src/libextra/list.rs @@ -27,7 +27,7 @@ pub enum MutList { /// Create a list from a vector pub fn from_vec(v: &[T]) -> @List { - v.rev_iter().fold(@Nil::, |t, h| @Cons(*h, t)) + v.rev_iter().fold(@Nil::, |t, h| @Cons(copy *h, t)) } /** @@ -61,7 +61,7 @@ pub fn find(ls: @List, f: &fn(&T) -> bool) -> Option { loop { ls = match *ls { Cons(ref hd, tl) => { - if f(hd) { return Some(*hd); } + if f(hd) { return Some(copy *hd); } tl } Nil => return None diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 972bccde18a..aee087d3764 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -179,7 +179,7 @@ impl SmallIntMap { ff: &fn(uint, V, V) -> V) -> bool { let new_val = match self.find(&key) { None => val, - Some(orig) => ff(key, *orig, val) + Some(orig) => ff(key, copy *orig, val) }; self.insert(key, new_val) } diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index b88fd374da2..b5645d9c501 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -37,7 +37,7 @@ pub fn merge_sort(v: &[T], le: Le) -> ~[T] { let v_len = end - begin; if v_len == 0 { return ~[]; } - if v_len == 1 { return ~[v[begin]]; } + if v_len == 1 { return ~[copy v[begin]]; } let mid = v_len / 2 + begin; let a = (begin, mid); @@ -53,9 +53,9 @@ pub fn merge_sort(v: &[T], le: Le) -> ~[T] { let mut b_ix = 0; while a_ix < a_len && b_ix < b_len { if le(&a[a_ix], &b[b_ix]) { - rs.push(a[a_ix]); + rs.push(copy a[a_ix]); a_ix += 1; - } else { rs.push(b[b_ix]); b_ix += 1; } + } else { rs.push(copy b[b_ix]); b_ix += 1; } } rs.push_all(vec::slice(a, a_ix, a_len)); rs.push_all(vec::slice(b, b_ix, b_len)); @@ -106,7 +106,7 @@ pub fn quick_sort(arr: &mut [T], compare_func: Le) { fn qsort3(arr: &mut [T], left: int, right: int) { if right <= left { return; } - let v: T = arr[right]; + let v: T = copy arr[right]; let mut i: int = left - 1; let mut j: int = right; let mut p: int = i; @@ -233,7 +233,7 @@ fn binarysort(array: &mut [T], start: uint) { if start == 0 { start += 1; } while start < size { - let pivot = array[start]; + let pivot = copy array[start]; let mut left = 0; let mut right = start; assert!(left <= right); @@ -470,7 +470,7 @@ impl MergeState { let mut tmp = ~[]; for uint::range(base1, base1+len1) |i| { - tmp.push(array[i]); + tmp.push(copy array[i]); } let mut c1 = 0; @@ -580,7 +580,7 @@ impl MergeState { let mut tmp = ~[]; for uint::range(base2, base2+len2) |i| { - tmp.push(array[i]); + tmp.push(copy array[i]); } let mut c1 = base1 + len1 - 1; @@ -732,7 +732,7 @@ fn copy_vec(dest: &mut [T], assert!(s1+from.len() <= dest.len()); for from.eachi |i, v| { - dest[s1+i] = *v; + dest[s1+i] = copy *v; } } @@ -1045,7 +1045,7 @@ mod big_tests { fn multiplyVec(arr: &[T], num: uint) -> ~[T] { let size = arr.len(); let res = do vec::from_fn(num) |i| { - arr[i % size] + copy arr[i % size] }; res } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 110f686e5a6..5d5d7582b5f 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1184,7 +1184,7 @@ fn create_index(index: ~[entry]) -> for uint::range(0u, 256u) |_i| { buckets.push(@mut ~[]); }; for index.each |elt| { let h = elt.val.hash() as uint; - buckets[h % 256].push(*elt); + buckets[h % 256].push(copy *elt); } let mut buckets_frozen = ~[]; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 7a8ebb4abfd..87c33ce64f5 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -200,8 +200,8 @@ fn cached_metadata(cache: metadata_cache, let items = cache.get(&mdtag); for items.each |item| { let md: T = md_from_metadata::(*item); - if eq_fn(md) { - return option::Some(md); + if eq_fn(copy md) { + return option::Some(copy md); } } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index b54f362c7d2..e161f35af09 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3694,7 +3694,7 @@ fn lookup_locally_or_in_crate_store( */ match map.find(&def_id) { - Some(&v) => { return v; } + Some(&ref v) => { return copy *v; } None => { } } @@ -3702,8 +3702,8 @@ fn lookup_locally_or_in_crate_store( fail!("No def'n found for %? in tcx.%s", def_id, descr); } let v = load_external(); - map.insert(def_id, v); - return v; + map.insert(def_id, copy v); + return copy v; } pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @Method { diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index 820bb2f86b0..7a3230079ee 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -89,10 +89,10 @@ impl CombineFields { // Need to make sub_id a subtype of sup_id. let node_a = self.infcx.get(a_id); let node_b = self.infcx.get(b_id); - let a_id = node_a.root; - let b_id = node_b.root; - let a_bounds = node_a.possible_types; - let b_bounds = node_b.possible_types; + let a_id = copy node_a.root; + let b_id = copy node_b.root; + let a_bounds = copy node_a.possible_types; + let b_bounds = copy node_b.possible_types; debug!("vars(%s=%s <: %s=%s)", a_id.to_str(), a_bounds.inf_str(self.infcx), @@ -102,8 +102,8 @@ impl CombineFields { // If both A's UB and B's LB have already been bound to types, // see if we can make those types subtypes. - match (a_bounds.ub, b_bounds.lb) { - (Some(ref a_ub), Some(ref b_lb)) => { + match (&a_bounds.ub, &b_bounds.lb) { + (&Some(ref a_ub), &Some(ref b_lb)) => { let r = self.infcx.try( || LatticeValue::sub(self, a_ub, b_lb)); match r { @@ -138,9 +138,9 @@ impl CombineFields { * Make a variable (`a_id`) a subtype of the concrete type `b` */ let node_a = self.infcx.get(a_id); - let a_id = node_a.root; + let a_id = copy node_a.root; let a_bounds = &node_a.possible_types; - let b_bounds = &Bounds { lb: None, ub: Some(b) }; + let b_bounds = &Bounds { lb: None, ub: Some(copy b) }; debug!("var_sub_t(%s=%s <: %s)", a_id.to_str(), @@ -161,9 +161,9 @@ impl CombineFields { * * Make a concrete type (`a`) a subtype of the variable `b_id` */ - let a_bounds = &Bounds { lb: Some(a), ub: None }; + let a_bounds = &Bounds { lb: Some(copy a), ub: None }; let node_b = self.infcx.get(b_id); - let b_id = node_b.root; + let b_id = copy node_b.root; let b_bounds = &node_b.possible_types; debug!("t_sub_var(%s <: %s=%s)", @@ -190,11 +190,11 @@ impl CombineFields { b.inf_str(self.infcx)); let _r = indenter(); - match (*a, *b) { - (None, None) => Ok(None), - (Some(_), None) => Ok(*a), - (None, Some(_)) => Ok(*b), - (Some(ref v_a), Some(ref v_b)) => { + match (a, b) { + (&None, &None) => Ok(None), + (&Some(_), &None) => Ok(copy *a), + (&None, &Some(_)) => Ok(copy *b), + (&Some(ref v_a), &Some(ref v_b)) => { do lattice_op(self, v_a, v_b).chain |v| { Ok(Some(v)) } @@ -272,13 +272,13 @@ impl CombineFields { b.inf_str(self.infcx)); let _r = indenter(); - match (*a, *b) { - (None, None) | - (Some(_), None) | - (None, Some(_)) => { + match (a, b) { + (&None, &None) | + (&Some(_), &None) | + (&None, &Some(_)) => { uok() } - (Some(ref t_a), Some(ref t_b)) => { + (&Some(ref t_a), &Some(ref t_b)) => { LatticeValue::sub(self, t_a, t_b) } } @@ -303,9 +303,9 @@ pub trait TyLatticeDir { impl LatticeDir for Lub { fn combine_fields(&self) -> CombineFields { **self } - fn bnd(&self, b: &Bounds) -> Option { b.ub } + fn bnd(&self, b: &Bounds) -> Option { copy b.ub } fn with_bnd(&self, b: &Bounds, t: T) -> Bounds { - Bounds { ub: Some(t), ..*b } + Bounds { ub: Some(t), ..copy *b } } } @@ -317,9 +317,9 @@ impl TyLatticeDir for Lub { impl LatticeDir for Glb { fn combine_fields(&self) -> CombineFields { **self } - fn bnd(&self, b: &Bounds) -> Option { b.lb } + fn bnd(&self, b: &Bounds) -> Option { copy b.lb } fn with_bnd(&self, b: &Bounds, t: T) -> Bounds { - Bounds { lb: Some(t), ..*b } + Bounds { lb: Some(t), ..copy *b } } } @@ -405,8 +405,8 @@ pub fn lattice_vars cres> { let nde_a = this.infcx().get(a_vid); let nde_b = this.infcx().get(b_vid); - let a_vid = nde_a.root; - let b_vid = nde_b.root; + let a_vid = copy nde_a.root; + let b_vid = copy nde_b.root; let a_bounds = &nde_a.possible_types; let b_bounds = &nde_b.possible_types; @@ -436,8 +436,8 @@ pub fn lattice_vars) -> cres { let nde_a = this.infcx().get(a_id); - let a_id = nde_a.root; + let a_id = copy nde_a.root; let a_bounds = &nde_a.possible_types; // The comments in this function are written for LUB, but they @@ -472,10 +472,11 @@ pub fn lattice_var_and_t { impl CresCompare for cres { fn compare(&self, t: T, f: &fn() -> ty::type_err) -> cres { - do self.chain |s| { + do (copy *self).chain |s| { if s == t { - *self + copy *self } else { Err(f()) } diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index c6e4b485d29..371d389f712 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -61,7 +61,7 @@ impl InferCtxt { { let vid_u = vid.to_uint(); let var_val = match vb.vals.find(&vid_u) { - Some(&var_val) => var_val, + Some(&ref var_val) => copy *var_val, None => { tcx.sess.bug(fmt!( "failed lookup of vid `%u`", vid_u)); @@ -69,11 +69,11 @@ impl InferCtxt { }; match var_val { Redirect(vid) => { - let node: Node = helper(tcx, vb, vid); + let node: Node = helper(tcx, vb, copy vid); if node.root != vid { // Path compression vb.vals.insert(vid.to_uint(), - Redirect(node.root)); + Redirect(copy node.root)); } node } @@ -96,12 +96,10 @@ impl InferCtxt { debug!("Updating variable %s to %s", vid.to_str(), new_v.inf_str(self)); - { // FIXME(#4903)---borrow checker is not flow sensitive - let vb = UnifyVid::appropriate_vals_and_bindings(self); - let old_v = { *vb.vals.get(&vid.to_uint()) }; // FIXME(#4903) - vb.bindings.push((vid, old_v)); - vb.vals.insert(vid.to_uint(), new_v); - } + let vb = UnifyVid::appropriate_vals_and_bindings(self); + let old_v = copy *vb.vals.get(&vid.to_uint()); + vb.bindings.push((copy vid, old_v)); + vb.vals.insert(vid.to_uint(), new_v); } pub fn unify node_b.rank { // a has greater rank, so a should become b's parent, // i.e., b should redirect to a. - self.set(node_b.root, Redirect(node_a.root)); - (node_a.root, node_a.rank) + self.set(copy node_b.root, Redirect(copy node_a.root)); + (copy node_a.root, node_a.rank) } else if node_a.rank < node_b.rank { // b has greater rank, so a should redirect to b. - self.set(node_a.root, Redirect(node_b.root)); - (node_b.root, node_b.rank) + self.set(copy node_a.root, Redirect(copy node_b.root)); + (copy node_b.root, node_b.rank) } else { // If equal, redirect one to the other and increment the // other's rank. assert_eq!(node_a.rank, node_b.rank); - self.set(node_b.root, Redirect(node_a.root)); - (node_a.root, node_a.rank + 1) + self.set(copy node_b.root, Redirect(copy node_a.root)); + (copy node_a.root, node_a.rank + 1) } } @@ -174,20 +172,20 @@ impl InferCtxt { let node_a = self.get(a_id); let node_b = self.get(b_id); - let a_id = node_a.root; - let b_id = node_b.root; + let a_id = copy node_a.root; + let b_id = copy node_b.root; if a_id == b_id { return uok(); } let combined = match (&node_a.possible_types, &node_b.possible_types) { (&None, &None) => None, - (&Some(ref v), &None) | (&None, &Some(ref v)) => Some(*v), + (&Some(ref v), &None) | (&None, &Some(ref v)) => Some(copy *v), (&Some(ref v1), &Some(ref v2)) => { if *v1 != *v2 { - return mk_err(a_is_expected, *v1, *v2); + return mk_err(a_is_expected, copy *v1, copy *v2); } - Some(*v1) + Some(copy *v1) } }; @@ -211,7 +209,7 @@ impl InferCtxt { * `b`. */ let node_a = self.get(a_id); - let a_id = node_a.root; + let a_id = copy node_a.root; match node_a.possible_types { None => { @@ -223,7 +221,7 @@ impl InferCtxt { if *a_t == b { return uok(); } else { - return mk_err(a_is_expected, *a_t, b); + return mk_err(a_is_expected, copy *a_t, b); } } } diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index a118e445fe2..56646eb4bfb 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -107,8 +107,8 @@ pub fn build_sized_opt(size: Option, #[inline(always)] pub fn append(lhs: @[T], rhs: &const [T]) -> @[T] { do build_sized(lhs.len() + rhs.len()) |push| { - for lhs.each |x| { push(*x); } - for uint::range(0, rhs.len()) |i| { push(rhs[i]); } + for lhs.each |x| { push(copy *x); } + for uint::range(0, rhs.len()) |i| { push(copy rhs[i]); } } } @@ -168,7 +168,7 @@ pub fn to_managed_consume(v: ~[T]) -> @[T] { * elements of a slice. */ pub fn to_managed(v: &[T]) -> @[T] { - from_fn(v.len(), |i| v[i]) + from_fn(v.len(), |i| copy v[i]) } #[cfg(not(test))] diff --git a/src/libstd/either.rs b/src/libstd/either.rs index fac0866f17e..e0451b2c65d 100644 --- a/src/libstd/either.rs +++ b/src/libstd/either.rs @@ -47,7 +47,7 @@ pub fn lefts(eithers: &[Either]) -> ~[T] { do vec::build_sized(eithers.len()) |push| { for eithers.each |elt| { match *elt { - Left(ref l) => { push(*l); } + Left(ref l) => { push(copy *l); } _ => { /* fallthrough */ } } } @@ -59,7 +59,7 @@ pub fn rights(eithers: &[Either]) -> ~[U] { do vec::build_sized(eithers.len()) |push| { for eithers.each |elt| { match *elt { - Right(ref r) => { push(*r); } + Right(ref r) => { push(copy *r); } _ => { /* fallthrough */ } } } diff --git a/src/libstd/io.rs b/src/libstd/io.rs index d3faa75e3b0..3e771c4ddde 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -1779,7 +1779,7 @@ pub mod fsync { None => (), Some(level) => { // fail hard if not succesful - assert!(((self.arg.fsync_fn)(self.arg.val, level) + assert!(((self.arg.fsync_fn)(copy self.arg.val, level) != -1)); } } diff --git a/src/libstd/num/num.rs b/src/libstd/num/num.rs index 4681e4f4f53..e7315624368 100644 --- a/src/libstd/num/num.rs +++ b/src/libstd/num/num.rs @@ -410,10 +410,10 @@ pub fn pow_with_uint+Mul>(radix: uint, pow let mut multiplier = cast(radix); while (my_pow > 0u) { if my_pow % 2u == 1u { - total *= multiplier; + total = total * multiplier; } - my_pow /= 2u; - multiplier *= multiplier; + my_pow = my_pow / 2u; + multiplier = multiplier * multiplier; } total } diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 3905d82cd0f..75c4fa98a2b 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -229,7 +229,7 @@ pub fn to_str_bytes_common+ // Initialize accumulator with signed zero for floating point parsing to // work - let mut accum = if accum_positive { _0 } else { -_1 * _0}; - let mut last_accum = accum; // Necessary to detect overflow + let mut accum = if accum_positive { copy _0 } else { -_1 * _0}; + let mut last_accum = copy accum; // Necessary to detect overflow let mut i = start; let mut exp_found = false; @@ -511,13 +511,13 @@ pub fn from_str_bytes_common+ match char::to_digit(c, radix) { Some(digit) => { // shift accum one digit left - accum *= radix_gen; + accum = accum * copy radix_gen; // add/subtract current digit depending on sign if accum_positive { - accum += cast(digit as int); + accum = accum + cast(digit as int); } else { - accum -= cast(digit as int); + accum = accum - cast(digit as int); } // Detect overflow by comparing to last value, except @@ -526,7 +526,7 @@ pub fn from_str_bytes_common+ if accum_positive && accum <= last_accum { return None; } if !accum_positive && accum >= last_accum { return None; } } - last_accum = accum; + last_accum = copy accum; } None => match c { '_' if ignore_underscores => {} @@ -548,7 +548,7 @@ pub fn from_str_bytes_common+ // Parse fractional part of number // Skip if already reached start of exponent if !exp_found { - let mut power = _1; + let mut power = copy _1; while i < len { let c = buf[i] as char; @@ -556,21 +556,21 @@ pub fn from_str_bytes_common+ match char::to_digit(c, radix) { Some(digit) => { // Decrease power one order of magnitude - power /= radix_gen; + power = power / radix_gen; let digit_t: T = cast(digit); // add/subtract current digit depending on sign if accum_positive { - accum += digit_t * power; + accum = accum + digit_t * power; } else { - accum -= digit_t * power; + accum = accum - digit_t * power; } // Detect overflow by comparing to last value if accum_positive && accum < last_accum { return None; } if !accum_positive && accum > last_accum { return None; } - last_accum = accum; + last_accum = copy accum; } None => match c { '_' if ignore_underscores => {} @@ -596,7 +596,7 @@ pub fn from_str_bytes_common+ } } - let mut multiplier = _1; + let mut multiplier = copy _1; if exp_found { let c = buf[i] as char; diff --git a/src/libstd/old_iter.rs b/src/libstd/old_iter.rs index 347b4774422..96bcf4e9107 100644 --- a/src/libstd/old_iter.rs +++ b/src/libstd/old_iter.rs @@ -115,7 +115,7 @@ pub fn filter_to_vec>(this: &IA, -> ~[A] { do vec::build_sized_opt(this.size_hint()) |push| { for this.each |a| { - if prd(a) { push(*a); } + if prd(a) { push(copy *a); } } } } @@ -191,7 +191,7 @@ pub fn position>(this: &IA, f: &fn(&A) -> bool) pub fn find>(this: &IA, f: &fn(&A) -> bool) -> Option { for this.each |i| { - if f(i) { return Some(*i) } + if f(i) { return Some(copy *i) } } return None; } @@ -270,7 +270,7 @@ pub fn from_fn>(n_elts: uint, op: InitOp) -> BT { pub fn from_elem>(n_elts: uint, t: T) -> BT { do Buildable::build_sized(n_elts) |push| { let mut i: uint = 0; - while i < n_elts { push(t); i += 1; } + while i < n_elts { push(copy t); i += 1; } } } @@ -281,8 +281,8 @@ pub fn append,BT:Buildable>(lhs: &IT, rhs: &IT) let size_opt = lhs.size_hint().chain_ref( |sz1| rhs.size_hint().map(|sz2| *sz1+*sz2)); do build_sized_opt(size_opt) |push| { - for lhs.each |x| { push(*x); } - for rhs.each |x| { push(*x); } + for lhs.each |x| { push(copy *x); } + for rhs.each |x| { push(copy *x); } } } @@ -291,6 +291,6 @@ pub fn append,BT:Buildable>(lhs: &IT, rhs: &IT) #[inline(always)] pub fn copy_seq,BT:Buildable>(v: &IT) -> BT { do build_sized_opt(v.size_hint()) |push| { - for v.each |x| { push(*x); } + for v.each |x| { push(copy *x); } } } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 76272706445..30394cb21af 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -88,14 +88,14 @@ impl Ord for Option { } } -impl> Add, Option> for Option { +impl> Add, Option> for Option { #[inline(always)] fn add(&self, other: &Option) -> Option { - match (*self, *other) { - (None, None) => None, - (_, None) => *self, - (None, _) => *other, - (Some(ref lhs), Some(ref rhs)) => Some(*lhs + *rhs) + match (&*self, &*other) { + (&None, &None) => None, + (_, &None) => copy *self, + (&None, _) => copy *other, + (&Some(ref lhs), &Some(ref rhs)) => Some(*lhs + *rhs) } } } diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 7946f7e4f13..2d73ed0c6a1 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -526,7 +526,7 @@ impl RngUtil for R { if values.is_empty() { None } else { - Some(values[self.gen_uint_range(0u, values.len())]) + Some(copy values[self.gen_uint_range(0u, values.len())]) } } /** @@ -555,7 +555,7 @@ impl RngUtil for R { for v.each |item| { so_far += item.weight; if so_far > chosen { - return Some(item.item); + return Some(copy item.item); } } util::unreachable(); @@ -569,7 +569,7 @@ impl RngUtil for R { let mut r = ~[]; for v.each |item| { for uint::range(0u, item.weight) |_i| { - r.push(item.item); + r.push(copy item.item); } } r diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index b80f152a5b1..c120883be5a 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -32,7 +32,7 @@ impl CopyableTuple for (T, U) { #[inline(always)] fn first(&self) -> T { match *self { - (t, _) => t, + (ref t, _) => copy *t, } } @@ -40,14 +40,14 @@ impl CopyableTuple for (T, U) { #[inline(always)] fn second(&self) -> U { match *self { - (_, u) => u, + (_, ref u) => copy *u, } } /// Return the results of swapping the two elements of self #[inline(always)] fn swap(&self) -> (U, T) { - match *self { + match copy *self { (t, u) => (u, t), } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 1a236a49a32..3f7bf897be2 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -167,7 +167,7 @@ pub fn from_elem(n_elts: uint, t: T) -> ~[T] { /// Creates a new unique vector with the same contents as the slice pub fn to_owned(t: &[T]) -> ~[T] { - from_fn(t.len(), |i| t[i]) + from_fn(t.len(), |i| copy t[i]) } /// Creates a new vector with a capacity of `capacity` @@ -441,9 +441,9 @@ pub fn partitioned(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) { for each(v) |elt| { if f(elt) { - lefts.push(*elt); + lefts.push(copy *elt); } else { - rights.push(*elt); + rights.push(copy *elt); } } @@ -798,7 +798,7 @@ pub fn grow(v: &mut ~[T], n: uint, initval: &T) { let mut i: uint = 0u; while i < n { - v.push(*initval); + v.push(copy *initval); i += 1u; } } @@ -970,7 +970,7 @@ pub fn filter(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] { pub fn filtered(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; for each(v) |elem| { - if f(elem) { result.push(*elem); } + if f(elem) { result.push(copy *elem); } } result } @@ -1026,7 +1026,7 @@ impl<'self, T:Copy> VectorVector for &'self [~[T]] { let mut r = ~[]; let mut first = true; for self.each |&inner| { - if first { first = false; } else { r.push(*sep); } + if first { first = false; } else { r.push(copy *sep); } r.push_all(inner); } r @@ -1044,7 +1044,7 @@ impl<'self, T:Copy> VectorVector for &'self [&'self [T]] { let mut r = ~[]; let mut first = true; for self.each |&inner| { - if first { first = false; } else { r.push(*sep); } + if first { first = false; } else { r.push(copy *sep); } r.push_all(inner); } r @@ -1077,7 +1077,7 @@ pub fn find(v: &[T], f: &fn(t: &T) -> bool) -> Option { */ pub fn find_between(v: &[T], start: uint, end: uint, f: &fn(t: &T) -> bool) -> Option { - position_between(v, start, end, f).map(|i| v[*i]) + position_between(v, start, end, f).map(|i| copy v[*i]) } /** @@ -1103,7 +1103,7 @@ pub fn rfind_between(v: &[T], end: uint, f: &fn(t: &T) -> bool) -> Option { - rposition_between(v, start, end, f).map(|i| v[*i]) + rposition_between(v, start, end, f).map(|i| copy v[*i]) } /// Find the first index containing a matching value @@ -1227,7 +1227,7 @@ pub fn bsearch_elem(v: &[T], x: &T) -> Option { pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { let mut (ts, us) = (~[], ~[]); for each(v) |p| { - let (t, u) = *p; + let (t, u) = copy *p; ts.push(t); us.push(u); } @@ -1262,7 +1262,7 @@ pub fn zip_slice(v: &const [T], u: &const [U]) let mut i = 0u; assert_eq!(sz, u.len()); while i < sz { - zipped.push((v[i], u[i])); + zipped.push((copy v[i], copy u[i])); i += 1u; } zipped @@ -1359,8 +1359,8 @@ pub fn reversed(v: &const [T]) -> ~[T] { let mut rs: ~[T] = ~[]; let mut i = v.len(); if i == 0 { return (rs); } else { i -= 1; } - while i != 0 { rs.push(v[i]); i -= 1; } - rs.push(v[0]); + while i != 0 { rs.push(copy v[i]); i -= 1; } + rs.push(copy v[0]); rs } @@ -1479,7 +1479,7 @@ pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool { */ pub fn each_permutation(values: &[T], fun: &fn(perm : &[T]) -> bool) -> bool { let length = values.len(); - let mut permutation = vec::from_fn(length, |i| values[i]); + let mut permutation = vec::from_fn(length, |i| copy values[i]); if length <= 1 { fun(permutation); return true; @@ -1506,7 +1506,7 @@ pub fn each_permutation(values: &[T], fun: &fn(perm : &[T]) -> bool) -> reverse_part(indices, k+1, length); // fixup permutation based on indices for uint::range(k, length) |i| { - permutation[i] = values[indices[i]]; + permutation[i] = copy values[indices[i]]; } } } @@ -2031,7 +2031,7 @@ impl<'self,T:Copy> ImmutableCopyableVector for &'self [T] { /// Returns the element at the given index, without doing bounds checking. #[inline(always)] unsafe fn unsafe_get(&self, index: uint) -> T { - *self.unsafe_ref(index) + copy *self.unsafe_ref(index) } } @@ -2350,7 +2350,7 @@ pub mod raw { */ #[inline(always)] pub unsafe fn get(v: &const [T], i: uint) -> T { - as_const_buf(v, |p, _len| *ptr::const_offset(p, i)) + as_const_buf(v, |p, _len| copy *ptr::const_offset(p, i)) } /** diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index cc89db6e189..07913946578 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -395,30 +395,30 @@ impl id_range { pub fn id_visitor(vfn: @fn(node_id, T)) -> visit::vt { let visit_generics: @fn(&Generics, T) = |generics, t| { for generics.ty_params.each |p| { - vfn(p.id, t); + vfn(p.id, copy t); } for generics.lifetimes.each |p| { - vfn(p.id, t); + vfn(p.id, copy t); } }; visit::mk_vt(@visit::Visitor { visit_mod: |m, sp, id, (t, vt)| { - vfn(id, t); + vfn(id, copy t); visit::visit_mod(m, sp, id, (t, vt)); }, visit_view_item: |vi, (t, vt)| { match vi.node { - view_item_extern_mod(_, _, id) => vfn(id, t), + view_item_extern_mod(_, _, id) => vfn(id, copy t), view_item_use(ref vps) => { for vps.each |vp| { match vp.node { - view_path_simple(_, _, id) => vfn(id, t), - view_path_glob(_, id) => vfn(id, t), + view_path_simple(_, _, id) => vfn(id, copy t), + view_path_glob(_, id) => vfn(id, copy t), view_path_list(_, ref paths, id) => { - vfn(id, t); + vfn(id, copy t); for paths.each |p| { - vfn(p.node.id, t); + vfn(p.node.id, copy t); } } } @@ -429,34 +429,34 @@ pub fn id_visitor(vfn: @fn(node_id, T)) -> visit::vt { }, visit_foreign_item: |ni, (t, vt)| { - vfn(ni.id, t); + vfn(ni.id, copy t); visit::visit_foreign_item(ni, (t, vt)); }, visit_item: |i, (t, vt)| { - vfn(i.id, t); + vfn(i.id, copy t); match i.node { item_enum(ref enum_definition, _) => - for (*enum_definition).variants.each |v| { vfn(v.node.id, t); }, + for (*enum_definition).variants.each |v| { vfn(v.node.id, copy t); }, _ => () } visit::visit_item(i, (t, vt)); }, visit_local: |l, (t, vt)| { - vfn(l.node.id, t); + vfn(l.node.id, copy t); visit::visit_local(l, (t, vt)); }, visit_block: |b, (t, vt)| { - vfn(b.node.id, t); + vfn(b.node.id, copy t); visit::visit_block(b, (t, vt)); }, visit_stmt: |s, (t, vt)| { - vfn(ast_util::stmt_id(s), t); + vfn(ast_util::stmt_id(s), copy t); visit::visit_stmt(s, (t, vt)); }, visit_pat: |p, (t, vt)| { - vfn(p.id, t); + vfn(p.id, copy t); visit::visit_pat(p, (t, vt)); }, @@ -464,36 +464,36 @@ pub fn id_visitor(vfn: @fn(node_id, T)) -> visit::vt { { let r = e.get_callee_id(); for r.iter().advance |callee_id| { - vfn(*callee_id, t); + vfn(*callee_id, copy t); } } - vfn(e.id, t); + vfn(e.id, copy t); visit::visit_expr(e, (t, vt)); }, visit_ty: |ty, (t, vt)| { match ty.node { - ty_path(_, id) => vfn(id, t), + ty_path(_, id) => vfn(id, copy t), _ => { /* fall through */ } } visit::visit_ty(ty, (t, vt)); }, visit_generics: |generics, (t, vt)| { - visit_generics(generics, t); + visit_generics(generics, copy t); visit::visit_generics(generics, (t, vt)); }, visit_fn: |fk, d, a, b, id, (t, vt)| { - vfn(id, t); + vfn(id, copy t); match *fk { visit::fk_item_fn(_, generics, _, _) => { - visit_generics(generics, t); + visit_generics(generics, copy t); } visit::fk_method(_, generics, m) => { - vfn(m.self_id, t); - visit_generics(generics, t); + vfn(m.self_id, copy t); + visit_generics(generics, copy t); } visit::fk_anon(_) | visit::fk_fn_block => { @@ -501,13 +501,13 @@ pub fn id_visitor(vfn: @fn(node_id, T)) -> visit::vt { } for d.inputs.each |arg| { - vfn(arg.id, t) + vfn(arg.id, copy t) } - visit::visit_fn(fk, d, a, b, id, (t, vt)); + visit::visit_fn(fk, d, a, b, id, (copy t, vt)); }, visit_struct_field: |f, (t, vt)| { - vfn(f.node.id, t); + vfn(f.node.id, copy t); visit::visit_struct_field(f, (t, vt)); }, diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 1704b4ef6c5..e67ca5260b8 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -318,7 +318,7 @@ pub fn expect(diag: @span_handler, opt: Option, msg: &fn() -> ~str) -> T { match opt { - Some(ref t) => (*t), + Some(ref t) => copy *t, None => diag.handler().bug(msg()) } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7eec9e2ee89..e72d9b502dc 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -322,7 +322,7 @@ pub fn commasep(s: @ps, b: breaks, elts: &[IN], op: &fn(@ps, IN)) { let mut first = true; for elts.each |elt| { if first { first = false; } else { word_space(s, ","); } - op(s, *elt); + op(s, copy *elt); } end(s); } @@ -334,13 +334,13 @@ pub fn commasep_cmnt(s: @ps, b: breaks, elts: &[IN], op: &fn(@ps, IN), let len = elts.len(); let mut i = 0u; for elts.each |elt| { - maybe_print_comment(s, get_span(*elt).hi); - op(s, *elt); + maybe_print_comment(s, get_span(copy *elt).hi); + op(s, copy *elt); i += 1u; if i < len { word(s.s, ","); - maybe_print_trailing_comment(s, get_span(*elt), - Some(get_span(elts[i]).hi)); + maybe_print_trailing_comment(s, get_span(copy *elt), + Some(get_span(copy elts[i]).hi)); space_if_not_bol(s); } } @@ -2118,7 +2118,7 @@ pub fn print_string(s: @ps, st: &str) { pub fn to_str(t: T, f: @fn(@ps, T), intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); - f(s, t); + f(s, copy t); eof(s.s); } } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index d4f183ada7b..bd5c178e7fe 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -36,7 +36,7 @@ impl Interner { pub fn prefill(init: &[T]) -> Interner { let rv = Interner::new(); - for init.each() |v| { rv.intern(*v); } + for init.each() |v| { rv.intern(copy *v); } rv } @@ -48,7 +48,7 @@ impl Interner { let vect = &mut *self.vect; let new_idx = vect.len(); - self.map.insert(val, new_idx); + self.map.insert(copy val, new_idx); vect.push(val); new_idx } @@ -63,7 +63,7 @@ impl Interner { new_idx } - pub fn get(&self, idx: uint) -> T { self.vect[idx] } + pub fn get(&self, idx: uint) -> T { copy self.vect[idx] } pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 6e753a8cc58..f24c393d7b4 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -127,15 +127,15 @@ pub fn visit_crate(c: &crate, (e, v): (E, vt)) { } pub fn visit_mod(m: &_mod, _sp: span, _id: node_id, (e, v): (E, vt)) { - for m.view_items.each |vi| { (v.visit_view_item)(*vi, (e, v)); } - for m.items.each |i| { (v.visit_item)(*i, (e, v)); } + for m.view_items.each |vi| { (v.visit_view_item)(*vi, (copy e, v)); } + for m.items.each |i| { (v.visit_item)(*i, (copy e, v)); } } pub fn visit_view_item(_vi: @view_item, (_e, _v): (E, vt)) { } pub fn visit_local(loc: @local, (e, v): (E, vt)) { - (v.visit_pat)(loc.node.pat, (e, v)); - (v.visit_ty)(loc.node.ty, (e, v)); + (v.visit_pat)(loc.node.pat, (copy e, v)); + (v.visit_ty)(loc.node.ty, (copy e, v)); match loc.node.init { None => (), Some(ex) => (v.visit_expr)(ex, (e, v)) @@ -149,8 +149,8 @@ fn visit_trait_ref(tref: @ast::trait_ref, (e, v): (E, vt)) { pub fn visit_item(i: @item, (e, v): (E, vt)) { match i.node { item_const(t, ex) => { - (v.visit_ty)(t, (e, v)); - (v.visit_expr)(ex, (e, v)); + (v.visit_ty)(t, (copy e, v)); + (v.visit_expr)(ex, (copy e, v)); } item_fn(ref decl, purity, abi, ref generics, ref body) => { (v.visit_fn)( @@ -170,15 +170,15 @@ pub fn visit_item(i: @item, (e, v): (E, vt)) { } item_mod(ref m) => (v.visit_mod)(m, i.span, i.id, (e, v)), item_foreign_mod(ref nm) => { - for nm.view_items.each |vi| { (v.visit_view_item)(*vi, (e, v)); } - for nm.items.each |ni| { (v.visit_foreign_item)(*ni, (e, v)); } + for nm.view_items.each |vi| { (v.visit_view_item)(*vi, (copy e, v)); } + for nm.items.each |ni| { (v.visit_foreign_item)(*ni, (copy e, v)); } } item_ty(t, ref tps) => { - (v.visit_ty)(t, (e, v)); + (v.visit_ty)(t, (copy e, v)); (v.visit_generics)(tps, (e, v)); } item_enum(ref enum_definition, ref tps) => { - (v.visit_generics)(tps, (e, v)); + (v.visit_generics)(tps, (copy e, v)); visit_enum_def( enum_definition, tps, @@ -186,24 +186,24 @@ pub fn visit_item(i: @item, (e, v): (E, vt)) { ); } item_impl(ref tps, ref traits, ty, ref methods) => { - (v.visit_generics)(tps, (e, v)); + (v.visit_generics)(tps, (copy e, v)); for traits.iter().advance |&p| { - visit_trait_ref(p, (e, v)); + visit_trait_ref(p, (copy e, v)); } - (v.visit_ty)(ty, (e, v)); + (v.visit_ty)(ty, (copy e, v)); for methods.each |m| { - visit_method_helper(*m, (e, v)) + visit_method_helper(*m, (copy e, v)) } } item_struct(struct_def, ref generics) => { - (v.visit_generics)(generics, (e, v)); + (v.visit_generics)(generics, (copy e, v)); (v.visit_struct_def)(struct_def, i.ident, generics, i.id, (e, v)); } item_trait(ref generics, ref traits, ref methods) => { - (v.visit_generics)(generics, (e, v)); - for traits.each |p| { visit_path(p.path, (e, v)); } + (v.visit_generics)(generics, (copy e, v)); + for traits.each |p| { visit_path(p.path, (copy e, v)); } for methods.each |m| { - (v.visit_trait_method)(m, (e, v)); + (v.visit_trait_method)(m, (copy e, v)); } } item_mac(ref m) => visit_mac(m, (e, v)) @@ -216,15 +216,19 @@ pub fn visit_enum_def(enum_definition: &ast::enum_def, for enum_definition.variants.each |vr| { match vr.node.kind { tuple_variant_kind(ref variant_args) => { - for variant_args.each |va| { (v.visit_ty)(va.ty, (e, v)); } + for variant_args.each |va| { + (v.visit_ty)(va.ty, (copy e, v)); + } } struct_variant_kind(struct_def) => { (v.visit_struct_def)(struct_def, vr.node.name, tps, - vr.node.id, (e, v)); + vr.node.id, (copy e, v)); } } // Visit the disr expr if it exists - for vr.node.disr_expr.iter().advance |ex| { (v.visit_expr)(*ex, (e, v)) } + for vr.node.disr_expr.iter().advance |ex| { + (v.visit_expr)(*ex, (copy e, v)) + } } } @@ -238,71 +242,75 @@ pub fn visit_ty(t: @Ty, (e, v): (E, vt)) { }, ty_tup(ref ts) => { for ts.each |tt| { - (v.visit_ty)(*tt, (e, v)); + (v.visit_ty)(*tt, (copy e, v)); } }, ty_closure(ref f) => { - for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, (e, v)); } + for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, (copy e, v)); } (v.visit_ty)(f.decl.output, (e, v)); }, ty_bare_fn(ref f) => { - for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, (e, v)); } + for f.decl.inputs.each |a| { (v.visit_ty)(a.ty, (copy e, v)); } (v.visit_ty)(f.decl.output, (e, v)); }, ty_path(p, _) => visit_path(p, (e, v)), ty_fixed_length_vec(ref mt, ex) => { - (v.visit_ty)(mt.ty, (e, v)); - (v.visit_expr)(ex, (e, v)); + (v.visit_ty)(mt.ty, (copy e, v)); + (v.visit_expr)(ex, (copy e, v)); }, ty_nil | ty_bot | ty_mac(_) | ty_infer => () } } pub fn visit_path(p: @Path, (e, v): (E, vt)) { - for p.types.each |tp| { (v.visit_ty)(*tp, (e, v)); } + for p.types.each |tp| { (v.visit_ty)(*tp, (copy e, v)); } } pub fn visit_pat(p: @pat, (e, v): (E, vt)) { match p.node { pat_enum(path, ref children) => { - visit_path(path, (e, v)); + visit_path(path, (copy e, v)); for children.iter().advance |children| { - for children.iter().advance |child| { (v.visit_pat)(*child, (e, v)); } + for children.iter().advance |child| { + (v.visit_pat)(*child, (copy e, v)); + } } } pat_struct(path, ref fields, _) => { - visit_path(path, (e, v)); + visit_path(path, (copy e, v)); for fields.each |f| { - (v.visit_pat)(f.pat, (e, v)); + (v.visit_pat)(f.pat, (copy e, v)); } } pat_tup(ref elts) => { for elts.each |elt| { - (v.visit_pat)(*elt, (e, v)) + (v.visit_pat)(*elt, (copy e, v)) } }, pat_box(inner) | pat_uniq(inner) | pat_region(inner) => { (v.visit_pat)(inner, (e, v)) }, pat_ident(_, path, ref inner) => { - visit_path(path, (e, v)); - for inner.iter().advance |subpat| { (v.visit_pat)(*subpat, (e, v)) } + visit_path(path, (copy e, v)); + for inner.iter().advance |subpat| { + (v.visit_pat)(*subpat, (copy e, v)) + } } pat_lit(ex) => (v.visit_expr)(ex, (e, v)), pat_range(e1, e2) => { - (v.visit_expr)(e1, (e, v)); + (v.visit_expr)(e1, (copy e, v)); (v.visit_expr)(e2, (e, v)); } pat_wild => (), pat_vec(ref before, ref slice, ref after) => { for before.each |elt| { - (v.visit_pat)(*elt, (e, v)); + (v.visit_pat)(*elt, (copy e, v)); } for slice.iter().advance |elt| { - (v.visit_pat)(*elt, (e, v)); + (v.visit_pat)(*elt, (copy e, v)); } for after.each |tail| { - (v.visit_pat)(*tail, (e, v)); + (v.visit_pat)(*tail, (copy e, v)); } } } @@ -311,7 +319,7 @@ pub fn visit_pat(p: @pat, (e, v): (E, vt)) { pub fn visit_foreign_item(ni: @foreign_item, (e, v): (E, vt)) { match ni.node { foreign_item_fn(ref fd, _, ref generics) => { - visit_fn_decl(fd, (e, v)); + visit_fn_decl(fd, (copy e, v)); (v.visit_generics)(generics, (e, v)); } foreign_item_const(t) => { @@ -324,7 +332,7 @@ pub fn visit_ty_param_bounds(bounds: @OptVec, (e, v): (E, vt)) { for bounds.each |bound| { match *bound { - TraitTyParamBound(ty) => visit_trait_ref(ty, (e, v)), + TraitTyParamBound(ty) => visit_trait_ref(ty, (copy e, v)), RegionTyParamBound => {} } } @@ -332,14 +340,14 @@ pub fn visit_ty_param_bounds(bounds: @OptVec, pub fn visit_generics(generics: &Generics, (e, v): (E, vt)) { for generics.ty_params.each |tp| { - visit_ty_param_bounds(tp.bounds, (e, v)); + visit_ty_param_bounds(tp.bounds, (copy e, v)); } } pub fn visit_fn_decl(fd: &fn_decl, (e, v): (E, vt)) { for fd.inputs.each |a| { - (v.visit_pat)(a.pat, (e, v)); - (v.visit_ty)(a.ty, (e, v)); + (v.visit_pat)(a.pat, (copy e, v)); + (v.visit_ty)(a.ty, (copy e, v)); } (v.visit_ty)(fd.output, (e, v)); } @@ -365,15 +373,15 @@ pub fn visit_method_helper(m: &method, (e, v): (E, vt)) { pub fn visit_fn(fk: &fn_kind, decl: &fn_decl, body: &blk, _sp: span, _id: node_id, (e, v): (E, vt)) { - visit_fn_decl(decl, (e, v)); + visit_fn_decl(decl, (copy e, v)); let generics = generics_of_fn(fk); - (v.visit_generics)(&generics, (e, v)); + (v.visit_generics)(&generics, (copy e, v)); (v.visit_block)(body, (e, v)); } pub fn visit_ty_method(m: &ty_method, (e, v): (E, vt)) { - for m.decl.inputs.each |a| { (v.visit_ty)(a.ty, (e, v)); } - (v.visit_generics)(&m.generics, (e, v)); + for m.decl.inputs.each |a| { (v.visit_ty)(a.ty, (copy e, v)); } + (v.visit_generics)(&m.generics, (copy e, v)); (v.visit_ty)(m.decl.output, (e, v)); } @@ -392,7 +400,7 @@ pub fn visit_struct_def( (e, v): (E, vt) ) { for sd.fields.each |f| { - (v.visit_struct_field)(*f, (e, v)); + (v.visit_struct_field)(*f, (copy e, v)); } } @@ -406,10 +414,10 @@ pub fn visit_struct_method(m: @method, (e, v): (E, vt)) { pub fn visit_block(b: &blk, (e, v): (E, vt)) { for b.node.view_items.each |vi| { - (v.visit_view_item)(*vi, (e, v)); + (v.visit_view_item)(*vi, (copy e, v)); } for b.node.stmts.each |s| { - (v.visit_stmt)(*s, (e, v)); + (v.visit_stmt)(*s, (copy e, v)); } visit_expr_opt(b.node.expr, (e, v)); } @@ -435,7 +443,7 @@ pub fn visit_expr_opt(eo: Option<@expr>, (e, v): (E, vt)) { } pub fn visit_exprs(exprs: &[@expr], (e, v): (E, vt)) { - for exprs.each |ex| { (v.visit_expr)(*ex, (e, v)); } + for exprs.each |ex| { (v.visit_expr)(*ex, (copy e, v)); } } pub fn visit_mac(_m: &mac, (_e, _v): (E, vt)) { @@ -444,53 +452,57 @@ pub fn visit_mac(_m: &mac, (_e, _v): (E, vt)) { pub fn visit_expr(ex: @expr, (e, v): (E, vt)) { match ex.node { - expr_vstore(x, _) => (v.visit_expr)(x, (e, v)), - expr_vec(ref es, _) => visit_exprs(*es, (e, v)), + expr_vstore(x, _) => (v.visit_expr)(x, (copy e, v)), + expr_vec(ref es, _) => visit_exprs(*es, (copy e, v)), expr_repeat(element, count, _) => { - (v.visit_expr)(element, (e, v)); - (v.visit_expr)(count, (e, v)); + (v.visit_expr)(element, (copy e, v)); + (v.visit_expr)(count, (copy e, v)); } expr_struct(p, ref flds, base) => { - visit_path(p, (e, v)); - for flds.each |f| { (v.visit_expr)(f.node.expr, (e, v)); } - visit_expr_opt(base, (e, v)); + visit_path(p, (copy e, v)); + for flds.each |f| { + (v.visit_expr)(f.node.expr, (copy e, v)); + } + visit_expr_opt(base, (copy e, v)); } expr_tup(ref elts) => { - for elts.each |el| { (v.visit_expr)(*el, (e, v)) } + for elts.each |el| { (v.visit_expr)(*el, (copy e, v)) } } expr_call(callee, ref args, _) => { - visit_exprs(*args, (e, v)); - (v.visit_expr)(callee, (e, v)); + visit_exprs(*args, (copy e, v)); + (v.visit_expr)(callee, (copy e, v)); } expr_method_call(_, callee, _, ref tys, ref args, _) => { - visit_exprs(*args, (e, v)); - for tys.each |tp| { (v.visit_ty)(*tp, (e, v)); } - (v.visit_expr)(callee, (e, v)); + visit_exprs(*args, (copy e, v)); + for tys.each |tp| { + (v.visit_ty)(*tp, (copy e, v)); + } + (v.visit_expr)(callee, (copy e, v)); } expr_binary(_, _, a, b) => { - (v.visit_expr)(a, (e, v)); - (v.visit_expr)(b, (e, v)); + (v.visit_expr)(a, (copy e, v)); + (v.visit_expr)(b, (copy e, v)); } expr_addr_of(_, x) | expr_unary(_, _, x) | - expr_loop_body(x) | expr_do_body(x) => (v.visit_expr)(x, (e, v)), + expr_loop_body(x) | expr_do_body(x) => (v.visit_expr)(x, (copy e, v)), expr_lit(_) => (), expr_cast(x, t) => { - (v.visit_expr)(x, (e, v)); - (v.visit_ty)(t, (e, v)); + (v.visit_expr)(x, (copy e, v)); + (v.visit_ty)(t, (copy e, v)); } expr_if(x, ref b, eo) => { - (v.visit_expr)(x, (e, v)); - (v.visit_block)(b, (e, v)); - visit_expr_opt(eo, (e, v)); + (v.visit_expr)(x, (copy e, v)); + (v.visit_block)(b, (copy e, v)); + visit_expr_opt(eo, (copy e, v)); } expr_while(x, ref b) => { - (v.visit_expr)(x, (e, v)); - (v.visit_block)(b, (e, v)); + (v.visit_expr)(x, (copy e, v)); + (v.visit_block)(b, (copy e, v)); } - expr_loop(ref b, _) => (v.visit_block)(b, (e, v)), + expr_loop(ref b, _) => (v.visit_block)(b, (copy e, v)), expr_match(x, ref arms) => { - (v.visit_expr)(x, (e, v)); - for arms.each |a| { (v.visit_arm)(a, (e, v)); } + (v.visit_expr)(x, (copy e, v)); + for arms.each |a| { (v.visit_arm)(a, (copy e, v)); } } expr_fn_block(ref decl, ref body) => { (v.visit_fn)( @@ -499,44 +511,46 @@ pub fn visit_expr(ex: @expr, (e, v): (E, vt)) { body, ex.span, ex.id, - (e, v) + (copy e, v) ); } - expr_block(ref b) => (v.visit_block)(b, (e, v)), + expr_block(ref b) => (v.visit_block)(b, (copy e, v)), expr_assign(a, b) => { - (v.visit_expr)(b, (e, v)); - (v.visit_expr)(a, (e, v)); + (v.visit_expr)(b, (copy e, v)); + (v.visit_expr)(a, (copy e, v)); } - expr_copy(a) => (v.visit_expr)(a, (e, v)), + expr_copy(a) => (v.visit_expr)(a, (copy e, v)), expr_assign_op(_, _, a, b) => { - (v.visit_expr)(b, (e, v)); - (v.visit_expr)(a, (e, v)); + (v.visit_expr)(b, (copy e, v)); + (v.visit_expr)(a, (copy e, v)); } expr_field(x, _, ref tys) => { - (v.visit_expr)(x, (e, v)); - for tys.each |tp| { (v.visit_ty)(*tp, (e, v)); } + (v.visit_expr)(x, (copy e, v)); + for tys.each |tp| { + (v.visit_ty)(*tp, (copy e, v)); + } } expr_index(_, a, b) => { - (v.visit_expr)(a, (e, v)); - (v.visit_expr)(b, (e, v)); + (v.visit_expr)(a, (copy e, v)); + (v.visit_expr)(b, (copy e, v)); } - expr_path(p) => visit_path(p, (e, v)), + expr_path(p) => visit_path(p, (copy e, v)), expr_self => (), expr_break(_) => (), expr_again(_) => (), - expr_ret(eo) => visit_expr_opt(eo, (e, v)), + expr_ret(eo) => visit_expr_opt(eo, (copy e, v)), expr_log(lv, x) => { - (v.visit_expr)(lv, (e, v)); - (v.visit_expr)(x, (e, v)); + (v.visit_expr)(lv, (copy e, v)); + (v.visit_expr)(x, (copy e, v)); } - expr_mac(ref mac) => visit_mac(mac, (e, v)), - expr_paren(x) => (v.visit_expr)(x, (e, v)), + expr_mac(ref mac) => visit_mac(mac, (copy e, v)), + expr_paren(x) => (v.visit_expr)(x, (copy e, v)), expr_inline_asm(ref a) => { for a.inputs.each |&(_, in)| { - (v.visit_expr)(in, (e, v)); + (v.visit_expr)(in, (copy e, v)); } for a.outputs.each |&(_, out)| { - (v.visit_expr)(out, (e, v)); + (v.visit_expr)(out, (copy e, v)); } } } @@ -544,9 +558,9 @@ pub fn visit_expr(ex: @expr, (e, v): (E, vt)) { } pub fn visit_arm(a: &arm, (e, v): (E, vt)) { - for a.pats.iter().advance |p| { (v.visit_pat)(*p, (e, v)); } - visit_expr_opt(a.guard, (e, v)); - (v.visit_block)(&a.body, (e, v)); + for a.pats.iter().advance |p| { (v.visit_pat)(*p, (copy e, v)); } + visit_expr_opt(a.guard, (copy e, v)); + (v.visit_block)(&a.body, (copy e, v)); } // Simpler, non-context passing interface. Always walks the whole tree, simply diff --git a/src/test/auxiliary/cci_capture_clause.rs b/src/test/auxiliary/cci_capture_clause.rs index e58b28aa3de..e45bfc8ea5d 100644 --- a/src/test/auxiliary/cci_capture_clause.rs +++ b/src/test/auxiliary/cci_capture_clause.rs @@ -14,7 +14,7 @@ use std::task; pub fn foo(x: T) -> Port { let (p, c) = stream(); do task::spawn() { - c.send(x); + c.send(copy x); } p } diff --git a/src/test/auxiliary/cci_nested_lib.rs b/src/test/auxiliary/cci_nested_lib.rs index 5701912b5f6..c0b98f2af07 100644 --- a/src/test/auxiliary/cci_nested_lib.rs +++ b/src/test/auxiliary/cci_nested_lib.rs @@ -25,7 +25,7 @@ pub fn alist_add(lst: &alist, k: A, v: B) { pub fn alist_get(lst: &alist, k: A) -> B { let eq_fn = lst.eq_fn; for lst.data.each |entry| { - if eq_fn(entry.key, k) { return entry.value; } + if eq_fn(copy entry.key, copy k) { return copy entry.value; } } fail!(); } diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 9fbc1d4590d..7a9be754884 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -30,9 +30,7 @@ use std::ptr; use std::uint; use std::vec; -macro_rules! move_out ( - { $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } } -) +fn move_out(x: T) {} enum request { get_count, @@ -91,7 +89,7 @@ fn run(args: &[~str]) { //error!("sending stop message"); to_child.send(stop); - move_out!(to_child); + move_out(to_child); let result = from_child.recv(); let end = extra::time::precise_time_s(); let elapsed = end - start; diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 2663bb26670..796072c8485 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -25,9 +25,7 @@ use std::task; use std::uint; use std::vec; -macro_rules! move_out ( - { $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } } -) +fn move_out(x: T) {} enum request { get_count, @@ -87,7 +85,7 @@ fn run(args: &[~str]) { //error!("sending stop message"); to_child.send(stop); - move_out!(to_child); + move_out(to_child); let result = from_child.recv(); let end = extra::time::precise_time_s(); let elapsed = end - start; diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index f2bb77b26ef..0f6ca37a3fb 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -34,10 +34,6 @@ proto! ring ( } ) -macro_rules! move_out ( - ($x:expr) => { unsafe { let y = *ptr::to_unsafe_ptr(&$x); y } } -) - fn thread_ring(i: uint, count: uint, num_chan: ring::client::num, @@ -54,7 +50,7 @@ fn thread_ring(i: uint, match recv(port) { ring::num(_n, p) => { //log(error, _n); - num_port = Some(move_out!(p)); + num_port = Some(p); } } }; diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index b7969fb0552..e12df5811ee 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -36,15 +36,15 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { fn le_by_val(kv0: &(TT,UU), kv1: &(TT,UU)) -> bool { - let (_, v0) = *kv0; - let (_, v1) = *kv1; + let (_, v0) = copy *kv0; + let (_, v1) = copy *kv1; return v0 >= v1; } fn le_by_key(kv0: &(TT,UU), kv1: &(TT,UU)) -> bool { - let (k0, _) = *kv0; - let (k1, _) = *kv1; + let (k0, _) = copy *kv0; + let (k1, _) = copy *kv1; return k0 <= k1; } diff --git a/src/test/compile-fail/infinite-instantiation.rs b/src/test/compile-fail/infinite-instantiation.rs index 605453d1bca..377b2016bcb 100644 --- a/src/test/compile-fail/infinite-instantiation.rs +++ b/src/test/compile-fail/infinite-instantiation.rs @@ -23,7 +23,7 @@ impl to_opt for uint { impl to_opt for Option { fn to_option(&self) -> Option> { - Some(*self) + Some(copy *self) } } diff --git a/src/test/compile-fail/kindck-owned.rs b/src/test/compile-fail/kindck-owned.rs index 27cc07ed123..ec84551f7b0 100644 --- a/src/test/compile-fail/kindck-owned.rs +++ b/src/test/compile-fail/kindck-owned.rs @@ -9,12 +9,13 @@ // except according to those terms. fn copy1(t: T) -> @fn() -> T { - let result: @fn() -> T = || t; //~ ERROR value may contain borrowed pointers + let result: @fn() -> T = || copy t; + //~^ ERROR value may contain borrowed pointers result } fn copy2(t: T) -> @fn() -> T { - let result: @fn() -> T = || t; + let result: @fn() -> T = || copy t; result } diff --git a/src/test/run-pass/alignment-gep-tup-like-1.rs b/src/test/run-pass/alignment-gep-tup-like-1.rs index bf96d6cfab5..6f1b4b81521 100644 --- a/src/test/run-pass/alignment-gep-tup-like-1.rs +++ b/src/test/run-pass/alignment-gep-tup-like-1.rs @@ -13,7 +13,7 @@ struct pair { } fn f(a: A, b: u16) -> @fn() -> (A, u16) { - let result: @fn() -> (A, u16) = || (a, b); + let result: @fn() -> (A, u16) = || (copy a, b); result } diff --git a/src/test/run-pass/alignment-gep-tup-like-2.rs b/src/test/run-pass/alignment-gep-tup-like-2.rs index 6bf4e96bc05..753e5339de9 100644 --- a/src/test/run-pass/alignment-gep-tup-like-2.rs +++ b/src/test/run-pass/alignment-gep-tup-like-2.rs @@ -24,7 +24,7 @@ fn make_cycle(a: A) { } fn f(a: A, b: B) -> @fn() -> (A, B) { - let result: @fn() -> (A, B) = || (a, b); + let result: @fn() -> (A, B) = || (copy a, copy b); result } diff --git a/src/test/run-pass/auto-encode.rs b/src/test/run-pass/auto-encode.rs index 7b03a699e78..6e5b837e0aa 100644 --- a/src/test/run-pass/auto-encode.rs +++ b/src/test/run-pass/auto-encode.rs @@ -41,6 +41,10 @@ fn test_ebml or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// just make sure this compiles: - -fn bar(x: *~int) -> ~int { - unsafe { - let y = *x; - return y; - } -} - -pub fn main() { -} diff --git a/src/test/run-pass/borrowed-ptr-pattern.rs b/src/test/run-pass/borrowed-ptr-pattern.rs index e0af2e80508..86e8f600cd5 100644 --- a/src/test/run-pass/borrowed-ptr-pattern.rs +++ b/src/test/run-pass/borrowed-ptr-pattern.rs @@ -10,7 +10,7 @@ fn foo(x: &T) -> T{ match x { - &a => a + &ref a => copy *a } } diff --git a/src/test/run-pass/box-unbox.rs b/src/test/run-pass/box-unbox.rs index e7dc4365679..f4fb10fea72 100644 --- a/src/test/run-pass/box-unbox.rs +++ b/src/test/run-pass/box-unbox.rs @@ -12,7 +12,7 @@ struct Box {c: @T} -fn unbox(b: Box) -> T { return *b.c; } +fn unbox(b: Box) -> T { return copy *b.c; } pub fn main() { let foo: int = 17; diff --git a/src/test/run-pass/close-over-big-then-small-data.rs b/src/test/run-pass/close-over-big-then-small-data.rs index 736c0f91941..69da3c8d986 100644 --- a/src/test/run-pass/close-over-big-then-small-data.rs +++ b/src/test/run-pass/close-over-big-then-small-data.rs @@ -17,7 +17,7 @@ struct Pair { } fn f(a: A, b: u16) -> @fn() -> (A, u16) { - let result: @fn() -> (A, u16) = || (a, b); + let result: @fn() -> (A, u16) = || (copy a, b); result } diff --git a/src/test/run-pass/expr-block-generic-box2.rs b/src/test/run-pass/expr-block-generic-box2.rs index 5d26fbdd789..9cf047d425c 100644 --- a/src/test/run-pass/expr-block-generic-box2.rs +++ b/src/test/run-pass/expr-block-generic-box2.rs @@ -14,7 +14,7 @@ type compare = @fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { - let actual: T = { expected }; + let actual: T = { copy expected }; assert!((eq(expected, actual))); } diff --git a/src/test/run-pass/expr-block-generic-unique2.rs b/src/test/run-pass/expr-block-generic-unique2.rs index 0d70bff3649..25bf553ff35 100644 --- a/src/test/run-pass/expr-block-generic-unique2.rs +++ b/src/test/run-pass/expr-block-generic-unique2.rs @@ -14,7 +14,7 @@ type compare = @fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { - let actual: T = { expected }; + let actual: T = { copy expected }; assert!((eq(expected, actual))); } diff --git a/src/test/run-pass/expr-block-generic.rs b/src/test/run-pass/expr-block-generic.rs index e507700e6b2..afb1a4c76bb 100644 --- a/src/test/run-pass/expr-block-generic.rs +++ b/src/test/run-pass/expr-block-generic.rs @@ -16,7 +16,7 @@ type compare = @fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { - let actual: T = { expected }; + let actual: T = { copy expected }; assert!((eq(expected, actual))); } diff --git a/src/test/run-pass/expr-if-generic-box2.rs b/src/test/run-pass/expr-if-generic-box2.rs index 12193037e11..186d15c3490 100644 --- a/src/test/run-pass/expr-if-generic-box2.rs +++ b/src/test/run-pass/expr-if-generic-box2.rs @@ -14,7 +14,7 @@ type compare = @fn(T, T) -> bool; fn test_generic(expected: T, not_expected: T, eq: compare) { - let actual: T = if true { expected } else { not_expected }; + let actual: T = if true { copy expected } else { not_expected }; assert!((eq(expected, actual))); } diff --git a/src/test/run-pass/expr-if-generic.rs b/src/test/run-pass/expr-if-generic.rs index 8d2ce83c879..2e6db3bba07 100644 --- a/src/test/run-pass/expr-if-generic.rs +++ b/src/test/run-pass/expr-if-generic.rs @@ -15,7 +15,7 @@ type compare = @fn(T, T) -> bool; fn test_generic(expected: T, not_expected: T, eq: compare) { - let actual: T = if true { expected } else { not_expected }; + let actual: T = if true { copy expected } else { not_expected }; assert!((eq(expected, actual))); } diff --git a/src/test/run-pass/expr-match-generic-box2.rs b/src/test/run-pass/expr-match-generic-box2.rs index c5c89b42825..64aa4ce3609 100644 --- a/src/test/run-pass/expr-match-generic-box2.rs +++ b/src/test/run-pass/expr-match-generic-box2.rs @@ -14,7 +14,7 @@ type compare = @fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { - let actual: T = match true { true => { expected }, _ => fail!("wat") }; + let actual: T = match true { true => { copy expected }, _ => fail!("wat") }; assert!((eq(expected, actual))); } diff --git a/src/test/run-pass/expr-match-generic.rs b/src/test/run-pass/expr-match-generic.rs index 04a229f2280..bd87e7207d1 100644 --- a/src/test/run-pass/expr-match-generic.rs +++ b/src/test/run-pass/expr-match-generic.rs @@ -14,7 +14,7 @@ type compare = @fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { - let actual: T = match true { true => { expected }, _ => fail!("wat") }; + let actual: T = match true { true => { copy expected }, _ => fail!("wat") }; assert!((eq(expected, actual))); } diff --git a/src/test/run-pass/generic-derived-type.rs b/src/test/run-pass/generic-derived-type.rs index 9e266a3f208..649fe3433b4 100644 --- a/src/test/run-pass/generic-derived-type.rs +++ b/src/test/run-pass/generic-derived-type.rs @@ -15,8 +15,7 @@ fn g(x: X) -> X { return x; } struct Pair {a: T, b: T} fn f(t: T) -> Pair { - - let x: Pair = Pair {a: t, b: t}; + let x: Pair = Pair {a: copy t, b: t}; return g::>(x); } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 4ef83e405be..014aebeff9d 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -233,9 +233,7 @@ pub mod pingpong { let addr : *::pipes::send_packet = match &p { &ping(ref x) => { cast::transmute(x) } }; - let liberated_value = *addr; - cast::forget(p); - liberated_value + fail!() } } @@ -244,9 +242,7 @@ pub mod pingpong { let addr : *::pipes::send_packet = match &p { &pong(ref x) => { cast::transmute(x) } }; - let liberated_value = *addr; - cast::forget(p); - liberated_value + fail!() } } diff --git a/src/test/run-pass/ivec-add.rs b/src/test/run-pass/ivec-add.rs index 80168daf62d..7cee6b4e8de 100644 --- a/src/test/run-pass/ivec-add.rs +++ b/src/test/run-pass/ivec-add.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn double(a: T) -> ~[T] { return ~[a] + ~[a]; } +fn double(a: T) -> ~[T] { return ~[copy a] + ~[a]; } -fn double_int(a: int) -> ~[int] { return ~[a] + ~[a]; } +fn double_int(a: int) -> ~[int] { return ~[copy a] + ~[a]; } pub fn main() { let mut d = double(1); diff --git a/src/test/run-pass/kindck-owned-trait-contains-1.rs b/src/test/run-pass/kindck-owned-trait-contains-1.rs index 35b5e077e7a..c51094d26c8 100644 --- a/src/test/run-pass/kindck-owned-trait-contains-1.rs +++ b/src/test/run-pass/kindck-owned-trait-contains-1.rs @@ -11,7 +11,7 @@ trait repeat { fn get(&self) -> A; } impl repeat for @A { - fn get(&self) -> A { **self } + fn get(&self) -> A { copy **self } } fn repeater(v: @A) -> @repeat { diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index f4ccd038afe..e091554a357 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -486,9 +486,9 @@ struct Stuff { } impl my_visitor { - pub fn get(&self, f: &fn(T)) { + pub fn get(&self, f: &fn(T)) { unsafe { - f(*(self.ptr1 as *T)); + f(copy *(self.ptr1 as *T)); } } diff --git a/src/test/run-pass/resource-generic.rs b/src/test/run-pass/resource-generic.rs index 41eafb0293a..7a18cd02c2d 100644 --- a/src/test/run-pass/resource-generic.rs +++ b/src/test/run-pass/resource-generic.rs @@ -20,7 +20,7 @@ struct finish { impl Drop for finish { fn finalize(&self) { unsafe { - (self.arg.fin)(self.arg.val); + (self.arg.fin)(copy self.arg.val); } } } diff --git a/src/test/run-pass/static-method-test.rs b/src/test/run-pass/static-method-test.rs index 4dde143f686..2d6b2141c5c 100644 --- a/src/test/run-pass/static-method-test.rs +++ b/src/test/run-pass/static-method-test.rs @@ -21,7 +21,7 @@ trait bool_like { } fn andand(x1: T, x2: T) -> T { - bool_like::select(x1, x2, x1) + bool_like::select(copy x1, x2, x1) } impl bool_like for bool {