Add copies to type params with Copy bound

This commit is contained in:
Niko Matsakis 2013-06-15 20:26:59 -04:00
parent 682bb4144c
commit eb48c29681
56 changed files with 380 additions and 390 deletions

View File

@ -264,31 +264,31 @@ mod tests {
fn test_parameterized<T:Copy + Eq>(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)]

View File

@ -111,7 +111,8 @@ pub fn from_elem<T>(data: T) -> @mut DList<T> {
/// Creates a new dlist from a vector of elements, maintaining the same order
pub fn from_vec<T:Copy>(vec: &[T]) -> @mut DList<T> {
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<T> DList<T> {
impl<T:Copy> DList<T> {
/// Remove data from the head of the list. O(1).
pub fn pop(@mut self) -> Option<T> {
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<T> {
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<T> {
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<T> {
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
}

View File

@ -57,7 +57,7 @@ priv enum FutureState<A> {
impl<A:Copy> Future<A> {
pub fn get(&mut self) -> A {
//! Get the value of the future.
*(self.get_ref())
copy *(self.get_ref())
}
}

View File

@ -27,7 +27,7 @@ pub enum MutList<T> {
/// Create a list from a vector
pub fn from_vec<T:Copy>(v: &[T]) -> @List<T> {
v.rev_iter().fold(@Nil::<T>, |t, h| @Cons(*h, t))
v.rev_iter().fold(@Nil::<T>, |t, h| @Cons(copy *h, t))
}
/**
@ -61,7 +61,7 @@ pub fn find<T:Copy>(ls: @List<T>, f: &fn(&T) -> bool) -> Option<T> {
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

View File

@ -179,7 +179,7 @@ impl<V:Copy> SmallIntMap<V> {
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)
}

View File

@ -37,7 +37,7 @@ pub fn merge_sort<T:Copy>(v: &[T], le: Le<T>) -> ~[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<T:Copy>(v: &[T], le: Le<T>) -> ~[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<T>(arr: &mut [T], compare_func: Le<T>) {
fn qsort3<T:Copy + Ord + Eq>(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<T:Copy + Ord>(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<T:Copy + Ord> MergeState<T> {
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<T:Copy + Ord> MergeState<T> {
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<T:Copy>(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<T:Copy>(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
}

View File

@ -1184,7 +1184,7 @@ fn create_index<T:Copy + Hash + IterBytes>(index: ~[entry<T>]) ->
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 = ~[];

View File

@ -200,8 +200,8 @@ fn cached_metadata<T:Copy>(cache: metadata_cache,
let items = cache.get(&mdtag);
for items.each |item| {
let md: T = md_from_metadata::<T>(*item);
if eq_fn(md) {
return option::Some(md);
if eq_fn(copy md) {
return option::Some(copy md);
}
}
}

View File

@ -3694,7 +3694,7 @@ fn lookup_locally_or_in_crate_store<V:Copy>(
*/
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<V:Copy>(
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 {

View File

@ -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<T:Copy>(&self, b: &Bounds<T>) -> Option<T> { b.ub }
fn bnd<T:Copy>(&self, b: &Bounds<T>) -> Option<T> { copy b.ub }
fn with_bnd<T:Copy>(&self, b: &Bounds<T>, t: T) -> Bounds<T> {
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<T:Copy>(&self, b: &Bounds<T>) -> Option<T> { b.lb }
fn bnd<T:Copy>(&self, b: &Bounds<T>) -> Option<T> { copy b.lb }
fn with_bnd<T:Copy>(&self, b: &Bounds<T>, t: T) -> Bounds<T> {
Bounds { lb: Some(t), ..*b }
Bounds { lb: Some(t), ..copy *b }
}
}
@ -405,8 +405,8 @@ pub fn lattice_vars<L:LatticeDir + Combine,
-> cres<LatticeVarResult<V,T>> {
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<L:LatticeDir + Combine,
// Otherwise, we need to merge A and B into one variable. We can
// then use either variable as an upper bound:
let cf = this.combine_fields();
do cf.var_sub_var(a_vid, b_vid).then {
Ok(VarResult(a_vid))
do cf.var_sub_var(copy a_vid, copy b_vid).then {
Ok(VarResult(copy a_vid))
}
}
@ -450,7 +450,7 @@ pub fn lattice_var_and_t<L:LatticeDir + Combine,
lattice_dir_op: LatticeDirOp<T>)
-> cres<T> {
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<L:LatticeDir + Combine,
// If a does not have an upper bound, make b the upper bound of a
// and then return b.
debug!("bnd=None");
let a_bounds = this.with_bnd(a_bounds, *b);
let a_bounds = this.with_bnd(a_bounds, copy *b);
do this.combine_fields().bnds(&a_bounds.lb, &a_bounds.ub).then {
this.infcx().set(a_id, Root(a_bounds, nde_a.rank));
Ok(*b)
this.infcx().set(copy a_id,
Root(copy a_bounds, copy nde_a.rank));
Ok(copy *b)
}
}
}

View File

@ -504,9 +504,9 @@ trait CresCompare<T> {
impl<T:Copy + Eq> CresCompare<T> for cres<T> {
fn compare(&self, t: T, f: &fn() -> ty::type_err) -> cres<T> {
do self.chain |s| {
do (copy *self).chain |s| {
if s == t {
*self
copy *self
} else {
Err(f())
}

View File

@ -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<V,T> = helper(tcx, vb, vid);
let node: Node<V,T> = 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<T:Copy + InferStr,
@ -120,18 +118,18 @@ impl InferCtxt {
if node_a.rank > 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);
}
}
}

View File

@ -107,8 +107,8 @@ pub fn build_sized_opt<A>(size: Option<uint>,
#[inline(always)]
pub fn append<T:Copy>(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<T>(v: ~[T]) -> @[T] {
* elements of a slice.
*/
pub fn to_managed<T:Copy>(v: &[T]) -> @[T] {
from_fn(v.len(), |i| v[i])
from_fn(v.len(), |i| copy v[i])
}
#[cfg(not(test))]

View File

@ -47,7 +47,7 @@ pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[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<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[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 */ }
}
}

View File

@ -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));
}
}

View File

@ -410,10 +410,10 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(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
}

View File

@ -229,7 +229,7 @@ pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
};
// Decrease the deccumulator one digit at a time
deccum /= radix_gen;
deccum = deccum / radix_gen;
deccum = deccum.round_to_zero();
buf.push(char::from_digit(current_digit.to_int() as uint, radix)
@ -282,7 +282,7 @@ pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
)
) {
// Shift first fractional digit into the integer part
deccum *= radix_gen;
deccum = deccum * radix_gen;
// Calculate the absolute value of each digit.
// See note in first loop.
@ -499,8 +499,8 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
// 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<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
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<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
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<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
// 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<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
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<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
}
}
let mut multiplier = _1;
let mut multiplier = copy _1;
if exp_found {
let c = buf[i] as char;

View File

@ -115,7 +115,7 @@ pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(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<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
pub fn find<A:Copy,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
-> Option<A> {
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<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
pub fn from_elem<T:Copy,BT:Buildable<T>>(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<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(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<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(lhs: &IT, rhs: &IT)
#[inline(always)]
pub fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(v: &IT) -> BT {
do build_sized_opt(v.size_hint()) |push| {
for v.each |x| { push(*x); }
for v.each |x| { push(copy *x); }
}
}

View File

@ -88,14 +88,14 @@ impl<T:Ord> Ord for Option<T> {
}
}
impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
impl<T: Copy+Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
#[inline(always)]
fn add(&self, other: &Option<T>) -> Option<T> {
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)
}
}
}

View File

@ -526,7 +526,7 @@ impl<R: Rng> 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<R: Rng> 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<R: Rng> 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

View File

@ -32,7 +32,7 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
#[inline(always)]
fn first(&self) -> T {
match *self {
(t, _) => t,
(ref t, _) => copy *t,
}
}
@ -40,14 +40,14 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> 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),
}
}

View File

@ -167,7 +167,7 @@ pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> ~[T] {
/// Creates a new unique vector with the same contents as the slice
pub fn to_owned<T:Copy>(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<T:Copy>(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<T:Copy>(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<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] {
pub fn filtered<T:Copy>(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<T> 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<T> 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<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
*/
pub fn find_between<T:Copy>(v: &[T], start: uint, end: uint,
f: &fn(t: &T) -> bool) -> Option<T> {
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<T:Copy>(v: &[T],
end: uint,
f: &fn(t: &T) -> bool)
-> Option<T> {
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<T:TotalOrd>(v: &[T], x: &T) -> Option<uint> {
pub fn unzip_slice<T:Copy,U:Copy>(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<T:Copy,U:Copy>(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<T:Copy>(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<T:Copy>(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<T:Copy>(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<T> 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<T:Copy>(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))
}
/**

View File

@ -395,30 +395,30 @@ impl id_range {
pub fn id_visitor<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> {
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<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> {
},
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<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> {
{
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<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> {
}
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));
},

View File

@ -318,7 +318,7 @@ pub fn expect<T:Copy>(diag: @span_handler,
opt: Option<T>,
msg: &fn() -> ~str) -> T {
match opt {
Some(ref t) => (*t),
Some(ref t) => copy *t,
None => diag.handler().bug(msg())
}
}

View File

@ -322,7 +322,7 @@ pub fn commasep<IN: Copy>(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<IN: Copy>(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: Copy>(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);
}
}

View File

@ -36,7 +36,7 @@ impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
pub fn prefill(init: &[T]) -> Interner<T> {
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<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
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<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
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() }

View File

@ -127,15 +127,15 @@ pub fn visit_crate<E: Copy>(c: &crate, (e, v): (E, vt<E>)) {
}
pub fn visit_mod<E: Copy>(m: &_mod, _sp: span, _id: node_id, (e, v): (E, vt<E>)) {
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<E>(_vi: @view_item, (_e, _v): (E, vt<E>)) { }
pub fn visit_local<E: Copy>(loc: @local, (e, v): (E, vt<E>)) {
(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<E: Copy>(tref: @ast::trait_ref, (e, v): (E, vt<E>)) {
pub fn visit_item<E: Copy>(i: @item, (e, v): (E, vt<E>)) {
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<E: Copy>(i: @item, (e, v): (E, vt<E>)) {
}
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<E: Copy>(i: @item, (e, v): (E, vt<E>)) {
);
}
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<E: Copy>(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<E: Copy>(t: @Ty, (e, v): (E, vt<E>)) {
},
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<E: Copy>(p: @Path, (e, v): (E, vt<E>)) {
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<E: Copy>(p: @pat, (e, v): (E, vt<E>)) {
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<E: Copy>(p: @pat, (e, v): (E, vt<E>)) {
pub fn visit_foreign_item<E: Copy>(ni: @foreign_item, (e, v): (E, vt<E>)) {
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<E: Copy>(bounds: @OptVec<TyParamBound>,
(e, v): (E, vt<E>)) {
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<E: Copy>(bounds: @OptVec<TyParamBound>,
pub fn visit_generics<E: Copy>(generics: &Generics, (e, v): (E, vt<E>)) {
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<E: Copy>(fd: &fn_decl, (e, v): (E, vt<E>)) {
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<E: Copy>(m: &method, (e, v): (E, vt<E>)) {
pub fn visit_fn<E: Copy>(fk: &fn_kind, decl: &fn_decl, body: &blk, _sp: span,
_id: node_id, (e, v): (E, vt<E>)) {
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<E: Copy>(m: &ty_method, (e, v): (E, vt<E>)) {
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: Copy>(
(e, v): (E, vt<E>)
) {
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<E: Copy>(m: @method, (e, v): (E, vt<E>)) {
pub fn visit_block<E: Copy>(b: &blk, (e, v): (E, vt<E>)) {
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<E>(eo: Option<@expr>, (e, v): (E, vt<E>)) {
}
pub fn visit_exprs<E: Copy>(exprs: &[@expr], (e, v): (E, vt<E>)) {
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<E>(_m: &mac, (_e, _v): (E, vt<E>)) {
@ -444,53 +452,57 @@ pub fn visit_mac<E>(_m: &mac, (_e, _v): (E, vt<E>)) {
pub fn visit_expr<E: Copy>(ex: @expr, (e, v): (E, vt<E>)) {
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<E: Copy>(ex: @expr, (e, v): (E, vt<E>)) {
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<E: Copy>(ex: @expr, (e, v): (E, vt<E>)) {
}
pub fn visit_arm<E: Copy>(a: &arm, (e, v): (E, vt<E>)) {
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

View File

@ -14,7 +14,7 @@ use std::task;
pub fn foo<T:Owned + Copy>(x: T) -> Port<T> {
let (p, c) = stream();
do task::spawn() {
c.send(x);
c.send(copy x);
}
p
}

View File

@ -25,7 +25,7 @@ pub fn alist_add<A:Copy,B:Copy>(lst: &alist<A,B>, k: A, v: B) {
pub fn alist_get<A:Copy,B:Copy>(lst: &alist<A,B>, 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!();
}

View File

@ -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<T>(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;

View File

@ -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<T>(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;

View File

@ -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);
}
}
};

View File

@ -36,15 +36,15 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
fn le_by_val<TT:Copy,UU:Copy + Ord>(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<TT:Copy + Ord,UU:Copy>(kv0: &(TT,UU),
kv1: &(TT,UU)) -> bool {
let (k0, _) = *kv0;
let (k1, _) = *kv1;
let (k0, _) = copy *kv0;
let (k1, _) = copy *kv1;
return k0 <= k1;
}

View File

@ -23,7 +23,7 @@ impl to_opt for uint {
impl<T:Copy> to_opt for Option<T> {
fn to_option(&self) -> Option<Option<T>> {
Some(*self)
Some(copy *self)
}
}

View File

@ -9,12 +9,13 @@
// except according to those terms.
fn copy1<T:Copy>(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:Copy + 'static>(t: T) -> @fn() -> T {
let result: @fn() -> T = || t;
let result: @fn() -> T = || copy t;
result
}

View File

@ -13,7 +13,7 @@ struct pair<A,B> {
}
fn f<A:Copy + 'static>(a: A, b: u16) -> @fn() -> (A, u16) {
let result: @fn() -> (A, u16) = || (a, b);
let result: @fn() -> (A, u16) = || (copy a, b);
result
}

View File

@ -24,7 +24,7 @@ fn make_cycle<A:Copy>(a: A) {
}
fn f<A:Owned + Copy,B:Owned + Copy>(a: A, b: B) -> @fn() -> (A, B) {
let result: @fn() -> (A, B) = || (a, b);
let result: @fn() -> (A, B) = || (copy a, copy b);
result
}

View File

@ -41,6 +41,10 @@ fn test_ebml<A:
let d = EBReader::Doc(@bytes);
let mut decoder = EBReader::Decoder(d);
let a2: A = Decodable::decode(&mut decoder);
if !(*a1 == a2) {
::std::sys::FailWithCause::fail_with(~"explicit failure" + "foo",
"auto-encode.rs", 43u);
}
assert!(*a1 == a2);
}
@ -137,42 +141,47 @@ pub fn main() {
let a = &Plus(@Minus(@Val(3u), @Val(10u)), @Plus(@Val(22u), @Val(5u)));
test_ebml(a);
let a = &Spanned {lo: 0u, hi: 5u, node: 22u};
test_ebml(a);
// let a = &Spanned {lo: 0u, hi: 5u, node: 22u};
// test_ebml(a);
let a = &Point {x: 3u, y: 5u};
test_ebml(a);
let a = &@[1u, 2u, 3u];
test_ebml(a);
let a = &Top(22u);
test_ebml(a);
let a = &Bottom(222u);
test_ebml(a);
let a = &A;
test_ebml(a);
let a = &B;
test_ebml(a);
// let a = &Point {x: 3u, y: 5u};
// test_ebml(a);
//
// let a = &@[1u, 2u, 3u];
// test_ebml(a);
//
// let a = &Top(22u);
// test_ebml(a);
//
// let a = &Bottom(222u);
// test_ebml(a);
//
// let a = &A;
// test_ebml(a);
//
// let a = &B;
// test_ebml(a);
println("Hi1");
let a = &time::now();
test_ebml(a);
test_ebml(&1.0f32);
test_ebml(&1.0f64);
println("Hi2");
// test_ebml(&1.0f32);
// test_ebml(&1.0f64);
test_ebml(&1.0f);
test_ebml(&'a');
// println("Hi3");
// test_ebml(&'a');
println("Hi4");
let mut a = HashMap::new();
test_ebml(&a);
a.insert(1, 2);
println("Hi4");
test_ebml(&a);
let mut a = HashSet::new();
test_ebml(&a);
a.insert(1);
test_ebml(&a);
// let mut a = HashSet::new();
// test_ebml(&a);
// a.insert(1);
// test_ebml(&a);
}

View File

@ -1,21 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {
}

View File

@ -10,7 +10,7 @@
fn foo<T:Copy>(x: &T) -> T{
match x {
&a => a
&ref a => copy *a
}
}

View File

@ -12,7 +12,7 @@
struct Box<T> {c: @T}
fn unbox<T:Copy>(b: Box<T>) -> T { return *b.c; }
fn unbox<T:Copy>(b: Box<T>) -> T { return copy *b.c; }
pub fn main() {
let foo: int = 17;

View File

@ -17,7 +17,7 @@ struct Pair<A,B> {
}
fn f<A:Copy + 'static>(a: A, b: u16) -> @fn() -> (A, u16) {
let result: @fn() -> (A, u16) = || (a, b);
let result: @fn() -> (A, u16) = || (copy a, b);
result
}

View File

@ -14,7 +14,7 @@
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
let actual: T = { copy expected };
assert!((eq(expected, actual)));
}

View File

@ -14,7 +14,7 @@
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
let actual: T = { copy expected };
assert!((eq(expected, actual)));
}

View File

@ -16,7 +16,7 @@
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = { expected };
let actual: T = { copy expected };
assert!((eq(expected, actual)));
}

View File

@ -14,7 +14,7 @@
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, not_expected: T, eq: compare<T>) {
let actual: T = if true { expected } else { not_expected };
let actual: T = if true { copy expected } else { not_expected };
assert!((eq(expected, actual)));
}

View File

@ -15,7 +15,7 @@
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, not_expected: T, eq: compare<T>) {
let actual: T = if true { expected } else { not_expected };
let actual: T = if true { copy expected } else { not_expected };
assert!((eq(expected, actual)));
}

View File

@ -14,7 +14,7 @@
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => { expected }, _ => fail!("wat") };
let actual: T = match true { true => { copy expected }, _ => fail!("wat") };
assert!((eq(expected, actual)));
}

View File

@ -14,7 +14,7 @@
type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => { expected }, _ => fail!("wat") };
let actual: T = match true { true => { copy expected }, _ => fail!("wat") };
assert!((eq(expected, actual)));
}

View File

@ -15,8 +15,7 @@ fn g<X:Copy>(x: X) -> X { return x; }
struct Pair<T> {a: T, b: T}
fn f<T:Copy>(t: T) -> Pair<T> {
let x: Pair<T> = Pair {a: t, b: t};
let x: Pair<T> = Pair {a: copy t, b: t};
return g::<Pair<T>>(x);
}

View File

@ -233,9 +233,7 @@ pub mod pingpong {
let addr : *::pipes::send_packet<pong> = 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<ping> = match &p {
&pong(ref x) => { cast::transmute(x) }
};
let liberated_value = *addr;
cast::forget(p);
liberated_value
fail!()
}
}

View File

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn double<T:Copy>(a: T) -> ~[T] { return ~[a] + ~[a]; }
fn double<T:Copy>(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);

View File

@ -11,7 +11,7 @@
trait repeat<A> { fn get(&self) -> A; }
impl<A:Copy> repeat<A> for @A {
fn get(&self) -> A { **self }
fn get(&self) -> A { copy **self }
}
fn repeater<A:Copy>(v: @A) -> @repeat<A> {

View File

@ -486,9 +486,9 @@ struct Stuff {
}
impl my_visitor {
pub fn get<T>(&self, f: &fn(T)) {
pub fn get<T:Copy>(&self, f: &fn(T)) {
unsafe {
f(*(self.ptr1 as *T));
f(copy *(self.ptr1 as *T));
}
}

View File

@ -20,7 +20,7 @@ struct finish<T> {
impl<T:Copy> Drop for finish<T> {
fn finalize(&self) {
unsafe {
(self.arg.fin)(self.arg.val);
(self.arg.fin)(copy self.arg.val);
}
}
}

View File

@ -21,7 +21,7 @@ trait bool_like {
}
fn andand<T:bool_like + Copy>(x1: T, x2: T) -> T {
bool_like::select(x1, x2, x1)
bool_like::select(copy x1, x2, x1)
}
impl bool_like for bool {