1
Fork 0

librustc: Remove all uses of the Copy bound.

This commit is contained in:
Patrick Walton 2013-07-10 14:43:25 -07:00
parent 99d44d24c7
commit e20549ff19
94 changed files with 213 additions and 280 deletions

View file

@ -85,7 +85,7 @@ fn map_slices<A:Clone + Send,B:Clone + Send>(
} }
/// A parallel version of map. /// A parallel version of map.
pub fn map<A:Copy + Clone + Send,B:Copy + Clone + Send>( pub fn map<A:Clone + Send,B:Clone + Send>(
xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] { xs: &[A], fn_factory: &fn() -> ~fn(&A) -> B) -> ~[B] {
vec::concat(map_slices(xs, || { vec::concat(map_slices(xs, || {
let f = fn_factory(); let f = fn_factory();
@ -96,7 +96,7 @@ pub fn map<A:Copy + Clone + Send,B:Copy + Clone + Send>(
} }
/// A parallel version of mapi. /// A parallel version of mapi.
pub fn mapi<A:Copy + Clone + Send,B:Copy + Clone + Send>( pub fn mapi<A:Clone + Send,B:Clone + Send>(
xs: &[A], xs: &[A],
fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B] { fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B] {
let slices = map_slices(xs, || { let slices = map_slices(xs, || {

View file

@ -650,10 +650,7 @@ impl<
} }
} }
impl< impl<S: Encoder, T: Encodable<S>> Encodable<S> for @mut DList<T> {
S: Encoder,
T: Encodable<S> + Copy
> Encodable<S> for DList<T> {
fn encode(&self, s: &mut S) { fn encode(&self, s: &mut S) {
do s.emit_seq(self.len()) |s| { do s.emit_seq(self.len()) |s| {
let mut i = 0; let mut i = 0;

View file

@ -24,12 +24,12 @@ type Le<'self, T> = &'self fn(v1: &T, v2: &T) -> bool;
* Has worst case O(n log n) performance, best case O(n), but * Has worst case O(n log n) performance, best case O(n), but
* is not space efficient. This is a stable sort. * is not space efficient. This is a stable sort.
*/ */
pub fn merge_sort<T:Copy + Clone>(v: &[T], le: Le<T>) -> ~[T] { pub fn merge_sort<T:Clone>(v: &[T], le: Le<T>) -> ~[T] {
type Slice = (uint, uint); type Slice = (uint, uint);
return merge_sort_(v, (0u, v.len()), le); return merge_sort_(v, (0u, v.len()), le);
fn merge_sort_<T:Copy + Clone>(v: &[T], slice: Slice, le: Le<T>) -> ~[T] { fn merge_sort_<T:Clone>(v: &[T], slice: Slice, le: Le<T>) -> ~[T] {
let begin = slice.first(); let begin = slice.first();
let end = slice.second(); let end = slice.second();
@ -44,7 +44,7 @@ pub fn merge_sort<T:Copy + Clone>(v: &[T], le: Le<T>) -> ~[T] {
merge_sort_(v, b, |x,y| le(x,y))); merge_sort_(v, b, |x,y| le(x,y)));
} }
fn merge<T:Copy + Clone>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] { fn merge<T:Clone>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
let mut rs = vec::with_capacity(a.len() + b.len()); let mut rs = vec::with_capacity(a.len() + b.len());
let a_len = a.len(); let a_len = a.len();
let mut a_ix = 0; let mut a_ix = 0;
@ -183,7 +183,7 @@ static MIN_GALLOP: uint = 7;
static INITIAL_TMP_STORAGE: uint = 128; static INITIAL_TMP_STORAGE: uint = 128;
#[allow(missing_doc)] #[allow(missing_doc)]
pub fn tim_sort<T:Copy + Clone + Ord>(array: &mut [T]) { pub fn tim_sort<T:Clone + Ord>(array: &mut [T]) {
let size = array.len(); let size = array.len();
if size < 2 { if size < 2 {
return; return;
@ -227,7 +227,7 @@ pub fn tim_sort<T:Copy + Clone + Ord>(array: &mut [T]) {
ms.merge_force_collapse(array); ms.merge_force_collapse(array);
} }
fn binarysort<T:Copy + Clone + Ord>(array: &mut [T], start: uint) { fn binarysort<T:Clone + Ord>(array: &mut [T], start: uint) {
let size = array.len(); let size = array.len();
let mut start = start; let mut start = start;
assert!(start <= size); assert!(start <= size);
@ -419,7 +419,7 @@ fn MergeState<T>() -> MergeState<T> {
} }
} }
impl<T:Copy + Clone + Ord> MergeState<T> { impl<T:Clone + Ord> MergeState<T> {
fn push_run(&mut self, run_base: uint, run_len: uint) { fn push_run(&mut self, run_base: uint, run_len: uint) {
let tmp = RunState{base: run_base, len: run_len}; let tmp = RunState{base: run_base, len: run_len};
self.runs.push(tmp); self.runs.push(tmp);
@ -739,10 +739,7 @@ fn copy_vec<T:Clone>(dest: &mut [T],
} }
#[inline] #[inline]
fn shift_vec<T:Copy + Clone>(dest: &mut [T], fn shift_vec<T:Clone>(dest: &mut [T], s1: uint, s2: uint, len: uint) {
s1: uint,
s2: uint,
len: uint) {
assert!(s1+len <= dest.len()); assert!(s1+len <= dest.len());
let tmp = dest.slice(s2, s2+len).to_owned(); let tmp = dest.slice(s2, s2+len).to_owned();

View file

@ -118,10 +118,8 @@ pub fn sleep(iotask: &IoTask, msecs: uint) {
* on the provided port in the allotted timeout period, then the result will * on the provided port in the allotted timeout period, then the result will
* be a `Some(T)`. If not, then `None` will be returned. * be a `Some(T)`. If not, then `None` will be returned.
*/ */
pub fn recv_timeout<T:Copy + Send>(iotask: &IoTask, pub fn recv_timeout<T:Send>(iotask: &IoTask, msecs: uint, wait_po: &Port<T>)
msecs: uint, -> Option<T> {
wait_po: &Port<T>)
-> Option<T> {
let (timeout_po, timeout_ch) = stream::<()>(); let (timeout_po, timeout_ch) = stream::<()>();
let mut timeout_po = timeout_po; let mut timeout_po = timeout_po;
delayed_send(iotask, msecs, &timeout_ch, ()); delayed_send(iotask, msecs, &timeout_ch, ());

View file

@ -43,19 +43,19 @@ impl ValidUsage {
} }
} }
enum Action<'self> { enum Action {
Call(&'self fn:Copy(args: &[~str]) -> ValidUsage), Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
CallMain(&'static str, &'self fn:Copy()), CallMain(&'static str, extern "Rust" fn()),
} }
enum UsageSource<'self> { enum UsageSource<'self> {
UsgStr(&'self str), UsgStr(&'self str),
UsgCall(&'self fn:Copy()), UsgCall(extern "Rust" fn()),
} }
struct Command<'self> { struct Command<'self> {
cmd: &'self str, cmd: &'self str,
action: Action<'self>, action: Action,
usage_line: &'self str, usage_line: &'self str,
usage_full: UsageSource<'self>, usage_full: UsageSource<'self>,
} }

View file

@ -199,8 +199,9 @@ pub fn compile_rest(sess: Session,
// //
// baz! should not use this definition unless foo is enabled. // baz! should not use this definition unless foo is enabled.
crate = time(time_passes, ~"std macros injection", || crate = time(time_passes, ~"std macros injection", ||
syntax::ext::expand::inject_std_macros(sess.parse_sess, copy cfg, syntax::ext::expand::inject_std_macros(sess.parse_sess,
crate)); cfg.clone(),
crate));
crate = time(time_passes, ~"configuration 1", || crate = time(time_passes, ~"configuration 1", ||
front::config::strip_unconfigured_items(crate)); front::config::strip_unconfigured_items(crate));

View file

@ -37,7 +37,7 @@ fn no_prelude(attrs: &[ast::attribute]) -> bool {
} }
fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate { fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
fn spanned<T:Copy>(x: T) -> codemap::spanned<T> { fn spanned<T>(x: T) -> codemap::spanned<T> {
codemap::spanned { node: x, span: dummy_sp() } codemap::spanned { node: x, span: dummy_sp() }
} }

View file

@ -343,7 +343,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item {
return @item; return @item;
} }
fn nospan<T:Copy>(t: T) -> codemap::spanned<T> { fn nospan<T>(t: T) -> codemap::spanned<T> {
codemap::spanned { node: t, span: dummy_sp() } codemap::spanned { node: t, span: dummy_sp() }
} }

View file

@ -87,7 +87,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
} as @FileSearch } as @FileSearch
} }
pub fn search<T:Copy>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> { pub fn search<T>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
let mut rslt = None; let mut rslt = None;
for filesearch.for_each_lib_search_path() |lib_search_path| { for filesearch.for_each_lib_search_path() |lib_search_path| {
debug!("searching %s", lib_search_path.to_str()); debug!("searching %s", lib_search_path.to_str());

View file

@ -1282,14 +1282,14 @@ fn test_more() {
fn test_simplification() { fn test_simplification() {
let ext_cx = mk_ctxt(); let ext_cx = mk_ctxt();
let item_in = ast::ii_item(quote_item!( let item_in = ast::ii_item(quote_item!(
fn new_int_alist<B:Copy>() -> alist<int, B> { fn new_int_alist<B>() -> alist<int, B> {
fn eq_int(a: int, b: int) -> bool { a == b } fn eq_int(a: int, b: int) -> bool { a == b }
return alist {eq_fn: eq_int, data: ~[]}; return alist {eq_fn: eq_int, data: ~[]};
} }
).get()); ).get());
let item_out = simplify_ast(&item_in); let item_out = simplify_ast(&item_in);
let item_exp = ast::ii_item(quote_item!( let item_exp = ast::ii_item(quote_item!(
fn new_int_alist<B:Copy>() -> alist<int, B> { fn new_int_alist<B>() -> alist<int, B> {
return alist {eq_fn: eq_int, data: ~[]}; return alist {eq_fn: eq_int, data: ~[]};
} }
).get()); ).get());

View file

@ -561,7 +561,7 @@ pub fn each_lint(sess: session::Session,
// This is used to make the simple visitors used for the lint passes // This is used to make the simple visitors used for the lint passes
// not traverse into subitems, since that is handled by the outer // not traverse into subitems, since that is handled by the outer
// lint visitor. // lint visitor.
fn item_stopping_visitor<E: Copy>(outer: visit::vt<E>) -> visit::vt<E> { fn item_stopping_visitor<E>(outer: visit::vt<E>) -> visit::vt<E> {
visit::mk_vt(@visit::Visitor { visit::mk_vt(@visit::Visitor {
visit_item: |_i, (_e, _v)| { }, visit_item: |_i, (_e, _v)| { },
visit_fn: |fk, fd, b, s, id, (e, v)| { visit_fn: |fk, fd, b, s, id, (e, v)| {

View file

@ -62,7 +62,7 @@ pub fn type_uses_for(ccx: @mut CrateContext, fn_id: def_id, n_tps: uint)
fn store_type_uses(cx: Context, fn_id: def_id) -> @~[type_uses] { fn store_type_uses(cx: Context, fn_id: def_id) -> @~[type_uses] {
let Context { uses, ccx } = cx; let Context { uses, ccx } = cx;
let uses = @copy *uses; // freeze let uses = @(*uses).clone(); // freeze
ccx.type_use_cache.insert(fn_id, uses); ccx.type_use_cache.insert(fn_id, uses);
uses uses
} }

View file

@ -860,7 +860,7 @@ fn mk_rcache() -> creader_cache {
return @mut HashMap::new(); return @mut HashMap::new();
} }
pub fn new_ty_hash<V:Copy>() -> @mut HashMap<t, V> { pub fn new_ty_hash<V>() -> @mut HashMap<t, V> {
@mut HashMap::new() @mut HashMap::new()
} }

View file

@ -1686,10 +1686,10 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
// through the `unpack` function. It there is no expected type or // through the `unpack` function. It there is no expected type or
// resolution is not possible (e.g., no constraints yet present), just // resolution is not possible (e.g., no constraints yet present), just
// returns `none`. // returns `none`.
fn unpack_expected<O:Copy>(fcx: @mut FnCtxt, fn unpack_expected<O>(fcx: @mut FnCtxt,
expected: Option<ty::t>, expected: Option<ty::t>,
unpack: &fn(&ty::sty) -> Option<O>) unpack: &fn(&ty::sty) -> Option<O>)
-> Option<O> { -> Option<O> {
match expected { match expected {
Some(t) => { Some(t) => {
match resolve_type(fcx.infcx(), t, force_tvar) { match resolve_type(fcx.infcx(), t, force_tvar) {

View file

@ -114,7 +114,8 @@ fn build_ctxt(sess: Session,
use rustc::front::config; use rustc::front::config;
let ast = syntax::ext::expand::inject_std_macros(sess.parse_sess, let ast = syntax::ext::expand::inject_std_macros(sess.parse_sess,
copy sess.opts.cfg, ast); sess.opts.cfg.clone(),
ast);
let ast = config::strip_unconfigured_items(ast); let ast = config::strip_unconfigured_items(ast);
let ast = syntax::ext::expand::expand_crate(sess.parse_sess, let ast = syntax::ext::expand::expand_crate(sess.parse_sess,
sess.opts.cfg.clone(), sess.opts.cfg.clone(),

View file

@ -208,8 +208,8 @@ mod test {
== ~"impl-of-selectt-u-for-left-right"); == ~"impl-of-selectt-u-for-left-right");
assert!(pandoc_header_id("impl of Condition<'self, T, U>") assert!(pandoc_header_id("impl of Condition<'self, T, U>")
== ~"impl-of-conditionself-t-u"); == ~"impl-of-conditionself-t-u");
assert!(pandoc_header_id("impl of Condition<T: Copy + Clone>") assert!(pandoc_header_id("impl of Condition<T: Clone>")
== ~"impl-of-conditiont-copy-clone"); == ~"impl-of-conditiont-clone");
} }
#[test] #[test]

View file

@ -394,8 +394,8 @@ mod test {
#[test] #[test]
fn should_add_impl_bounds() { fn should_add_impl_bounds() {
let doc = mk_doc(~"impl<T, U: Copy, V: Copy + Clone> Option<T, U, V> { }"); let doc = mk_doc(~"impl<T, U, V: Clone> Option<T, U, V> { }");
assert!(doc.cratemod().impls()[0].bounds_str == Some(~"<T, U: Copy, V: Copy + Clone>")); assert!(doc.cratemod().impls()[0].bounds_str == Some(~"<T, U, V: Clone>"));
} }
#[test] #[test]

View file

@ -839,7 +839,7 @@ fn install_check_duplicates() {
fail!("package database contains duplicate ID"); fail!("package database contains duplicate ID");
} }
else { else {
contents.push(copy *p); contents.push((*p).clone());
} }
false false
}; };

View file

@ -15,10 +15,9 @@ assign them or pass them as arguments, the receiver will get a copy,
leaving the original value in place. These types do not require leaving the original value in place. These types do not require
allocation to copy and do not have finalizers (i.e. they do not allocation to copy and do not have finalizers (i.e. they do not
contain owned boxes or implement `Drop`), so the compiler considers contain owned boxes or implement `Drop`), so the compiler considers
them cheap and safe to copy and automatically implements the `Copy` them cheap and safe to copy. For other types copies must be made
trait for them. For other types copies must be made explicitly, explicitly, by convention implementing the `Clone` trait and calling
by convention implementing the `Clone` trait and calling the the `clone` method.
`clone` method.
*/ */

View file

@ -47,7 +47,7 @@ impl<T, U> Condition<T, U> {
pub fn raise(&self, t: T) -> U { pub fn raise(&self, t: T) -> U {
let msg = fmt!("Unhandled condition: %s: %?", self.name, t); let msg = fmt!("Unhandled condition: %s: %?", self.name, t);
self.raise_default(t, || fail!(copy msg)) self.raise_default(t, || fail!(msg.clone()))
} }
pub fn raise_default(&self, t: T, default: &fn() -> U) -> U { pub fn raise_default(&self, t: T, default: &fn() -> U) -> U {
@ -78,7 +78,8 @@ impl<'self, T, U> Condition<'self, T, U> {
pub fn trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U> { pub fn trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U> {
unsafe { unsafe {
let p : *RustClosure = ::cast::transmute(&h); let p : *RustClosure = ::cast::transmute(&h);
let prev = local_data::get(self.key, |k| k.map(|&x| *x)); let prev = local_data::get(::cast::unsafe_copy(&self.key),
|k| k.map(|&x| *x));
let h = @Handler { handle: *p, prev: prev }; let h = @Handler { handle: *p, prev: prev };
Trap { cond: self, handler: h } Trap { cond: self, handler: h }
} }
@ -91,7 +92,7 @@ impl<'self, T, U> Condition<'self, T, U> {
pub fn raise_default(&self, t: T, default: &fn() -> U) -> U { pub fn raise_default(&self, t: T, default: &fn() -> U) -> U {
unsafe { unsafe {
match local_data::pop(self.key) { match local_data::pop(::cast::unsafe_copy(&self.key)) {
None => { None => {
debug!("Condition.raise: found no handler"); debug!("Condition.raise: found no handler");
default() default()
@ -100,12 +101,15 @@ impl<'self, T, U> Condition<'self, T, U> {
debug!("Condition.raise: found handler"); debug!("Condition.raise: found handler");
match handler.prev { match handler.prev {
None => {} None => {}
Some(hp) => local_data::set(self.key, hp) Some(hp) => {
local_data::set(::cast::unsafe_copy(&self.key),
hp)
}
} }
let handle : &fn(T) -> U = let handle : &fn(T) -> U =
::cast::transmute(handler.handle); ::cast::transmute(handler.handle);
let u = handle(t); let u = handle(t);
local_data::set(self.key, handler); local_data::set(::cast::unsafe_copy(&self.key), handler);
u u
} }
} }

View file

@ -18,22 +18,13 @@ intrinsic properties of the type. These classifications, often called
They cannot be implemented by user code, but are instead implemented They cannot be implemented by user code, but are instead implemented
by the compiler automatically for the types to which they apply. by the compiler automatically for the types to which they apply.
The 3 kinds are The 2 kinds are
* Copy - types that may be copied without allocation. This includes
scalar types and managed pointers, and exludes owned pointers. It
also excludes types that implement `Drop`.
* Send - owned types and types containing owned types. These types * Send - owned types and types containing owned types. These types
may be transferred across task boundaries. may be transferred across task boundaries.
* Freeze - types that are deeply immutable. * Freeze - types that are deeply immutable.
`Copy` types include both implicitly copyable types that the compiler
will copy automatically and non-implicitly copyable types that require
the `copy` keyword to copy. Types that do not implement `Copy` may
instead implement `Clone`.
*/ */
#[allow(missing_doc)]; #[allow(missing_doc)];

View file

@ -59,7 +59,7 @@ use task::local_data_priv::*;
#[cfg(not(stage0))] #[cfg(not(stage0))]
pub type Key<T> = &'static KeyValue<T>; pub type Key<T> = &'static KeyValue<T>;
#[cfg(stage0)] #[cfg(stage0)]
pub type Key<'self,T> = &'self fn:Copy(v: T); pub type Key<'self,T> = &'self fn(v: T);
pub enum KeyValue<T> { Key } pub enum KeyValue<T> { Key }

View file

@ -16,7 +16,6 @@ use cmp::{Eq, ApproxEq, Ord};
use ops::{Add, Sub, Mul, Div, Rem, Neg}; use ops::{Add, Sub, Mul, Div, Rem, Neg};
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr}; use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
use option::Option; use option::Option;
use kinds::Copy;
pub mod strconv; pub mod strconv;
@ -428,7 +427,7 @@ pub trait FromStrRadix {
/// - If code written to use this function doesn't care about it, it's /// - If code written to use this function doesn't care about it, it's
/// probably assuming that `x^0` always equals `1`. /// probably assuming that `x^0` always equals `1`.
/// ///
pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(radix: uint, pow: uint) -> T { pub fn pow_with_uint<T:NumCast+One+Zero+Div<T,T>+Mul<T,T>>(radix: uint, pow: uint) -> T {
let _0: T = Zero::zero(); let _0: T = Zero::zero();
let _1: T = One::one(); let _1: T = One::one();

View file

@ -16,9 +16,8 @@ use core::cmp::{Ord, Eq};
use ops::{Add, Sub, Mul, Div, Rem, Neg}; use ops::{Add, Sub, Mul, Div, Rem, Neg};
use option::{None, Option, Some}; use option::{None, Option, Some};
use char; use char;
use str::{StrSlice};
use str; use str;
use str::StrSlice;
use kinds::Copy;
use vec::{CopyableVector, ImmutableVector, MutableVector}; use vec::{CopyableVector, ImmutableVector, MutableVector};
use vec::OwnedVector; use vec::OwnedVector;
use num::{NumCast, Zero, One, cast, pow_with_uint, Integer}; use num::{NumCast, Zero, One, cast, pow_with_uint, Integer};
@ -466,7 +465,7 @@ priv static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
* - Fails if `radix` > 18 and `special == true` due to conflict * - Fails if `radix` > 18 and `special == true` due to conflict
* between digit and lowest first character in `inf` and `NaN`, the `'i'`. * between digit and lowest first character in `inf` and `NaN`, the `'i'`.
*/ */
pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Div<T,T>+
Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+ Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+
NumStrConv+Clone>( NumStrConv+Clone>(
buf: &[u8], radix: uint, negative: bool, fractional: bool, buf: &[u8], radix: uint, negative: bool, fractional: bool,
@ -663,7 +662,7 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
* `from_str_bytes_common()`, for details see there. * `from_str_bytes_common()`, for details see there.
*/ */
#[inline] #[inline]
pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+Mul<T,T>+ pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Div<T,T>+Mul<T,T>+
Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv+Clone>( Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv+Clone>(
buf: &str, radix: uint, negative: bool, fractional: bool, buf: &str, radix: uint, negative: bool, fractional: bool,
special: bool, exponent: ExponentFormat, empty_zero: bool, special: bool, exponent: ExponentFormat, empty_zero: bool,

View file

@ -29,7 +29,7 @@ Rust's prelude has three main parts:
// Reexported core operators // Reexported core operators
pub use either::{Either, Left, Right}; pub use either::{Either, Left, Right};
pub use kinds::{Copy, Sized}; pub use kinds::Sized;
pub use kinds::{Freeze, Send}; pub use kinds::{Freeze, Send};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not}; pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor}; pub use ops::{BitAnd, BitOr, BitXor};

View file

@ -356,7 +356,7 @@ pub trait RngUtil {
* } * }
* ~~~ * ~~~
*/ */
fn choose<T:Copy + Clone>(&mut self, values: &[T]) -> T; fn choose<T:Clone>(&mut self, values: &[T]) -> T;
/// Choose Some(item) randomly, returning None if values is empty /// Choose Some(item) randomly, returning None if values is empty
fn choose_option<T:Clone>(&mut self, values: &[T]) -> Option<T>; fn choose_option<T:Clone>(&mut self, values: &[T]) -> Option<T>;
/** /**
@ -379,7 +379,7 @@ pub trait RngUtil {
* } * }
* ~~~ * ~~~
*/ */
fn choose_weighted<T:Copy + Clone>(&mut self, v : &[Weighted<T>]) -> T; fn choose_weighted<T:Clone>(&mut self, v : &[Weighted<T>]) -> T;
/** /**
* Choose Some(item) respecting the relative weights, returning none if * Choose Some(item) respecting the relative weights, returning none if
* the sum of the weights is 0 * the sum of the weights is 0
@ -439,7 +439,7 @@ pub trait RngUtil {
* } * }
* ~~~ * ~~~
*/ */
fn shuffle<T:Copy + Clone>(&mut self, values: &[T]) -> ~[T]; fn shuffle<T:Clone>(&mut self, values: &[T]) -> ~[T];
/** /**
* Shuffle a mutable vec in place * Shuffle a mutable vec in place
* *
@ -532,7 +532,7 @@ impl<R: Rng> RngUtil for R {
} }
/// Choose an item randomly, failing if values is empty /// Choose an item randomly, failing if values is empty
fn choose<T:Copy + Clone>(&mut self, values: &[T]) -> T { fn choose<T:Clone>(&mut self, values: &[T]) -> T {
self.choose_option(values).get() self.choose_option(values).get()
} }
@ -548,7 +548,7 @@ impl<R: Rng> RngUtil for R {
* Choose an item respecting the relative weights, failing if the sum of * Choose an item respecting the relative weights, failing if the sum of
* the weights is 0 * the weights is 0
*/ */
fn choose_weighted<T:Copy + Clone>(&mut self, v: &[Weighted<T>]) -> T { fn choose_weighted<T:Clone>(&mut self, v: &[Weighted<T>]) -> T {
self.choose_weighted_option(v).get() self.choose_weighted_option(v).get()
} }
@ -591,7 +591,7 @@ impl<R: Rng> RngUtil for R {
} }
/// Shuffle a vec /// Shuffle a vec
fn shuffle<T:Copy + Clone>(&mut self, values: &[T]) -> ~[T] { fn shuffle<T:Clone>(&mut self, values: &[T]) -> ~[T] {
let mut m = values.to_owned(); let mut m = values.to_owned();
self.shuffle_mut(m); self.shuffle_mut(m);
m m

View file

@ -15,6 +15,7 @@ use libc;
use local_data; use local_data;
use prelude::*; use prelude::*;
use ptr; use ptr;
use sys;
use task::rt; use task::rt;
use util; use util;
@ -156,8 +157,9 @@ unsafe fn get_local_map(handle: Handle) -> &mut TaskLocalMap {
} }
} }
fn key_to_key_value<T: 'static>(key: local_data::Key<T>) -> *libc::c_void { unsafe fn key_to_key_value<T: 'static>(key: local_data::Key<T>) -> *libc::c_void {
unsafe { cast::transmute(key) } let pair: sys::Closure = cast::transmute_copy(&key);
return pair.code as *libc::c_void;
} }
pub unsafe fn local_pop<T: 'static>(handle: Handle, pub unsafe fn local_pop<T: 'static>(handle: Handle,

View file

@ -264,7 +264,8 @@ struct TrieNode<T> {
impl<T> TrieNode<T> { impl<T> TrieNode<T> {
#[inline] #[inline]
fn new() -> TrieNode<T> { fn new() -> TrieNode<T> {
// FIXME: #5244: [Nothing, ..SIZE] should be possible without Copy // FIXME: #5244: [Nothing, ..SIZE] should be possible without implicit
// copyability
TrieNode{count: 0, TrieNode{count: 0,
children: [Nothing, Nothing, Nothing, Nothing, children: [Nothing, Nothing, Nothing, Nothing,
Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing,

View file

@ -13,7 +13,6 @@
#[allow(missing_doc)]; #[allow(missing_doc)];
use clone::Clone; use clone::Clone;
use kinds::Copy;
use vec; use vec;
use vec::ImmutableVector; use vec::ImmutableVector;
use iterator::IteratorUtil; use iterator::IteratorUtil;
@ -86,8 +85,8 @@ pub trait ExtendedTupleOps<A,B> {
} }
impl<'self, impl<'self,
A:Copy + Clone, A:Clone,
B:Copy + Clone> B:Clone>
ExtendedTupleOps<A,B> for ExtendedTupleOps<A,B> for
(&'self [A], &'self [B]) { (&'self [A], &'self [B]) {
#[inline] #[inline]
@ -109,10 +108,7 @@ impl<'self,
} }
} }
impl<A:Copy + Clone, impl<A:Clone, B:Clone> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
B:Copy + Clone>
ExtendedTupleOps<A,B> for
(~[A], ~[B]) {
#[inline] #[inline]
fn zip(&self) -> ~[(A, B)] { fn zip(&self) -> ~[(A, B)] {
match *self { match *self {

View file

@ -16,11 +16,13 @@ use opt_vec;
use parse::token; use parse::token;
use visit; use visit;
use std::cast::unsafe_copy;
use std::cast;
use std::hashmap::HashMap; use std::hashmap::HashMap;
use std::int; use std::int;
use std::local_data;
use std::num; use std::num;
use std::option; use std::option;
use std::local_data;
pub fn path_name_i(idents: &[ident]) -> ~str { pub fn path_name_i(idents: &[ident]) -> ~str {
// FIXME: Bad copies (#2543 -- same for everything else that says "bad") // FIXME: Bad copies (#2543 -- same for everything else that says "bad")

View file

@ -414,7 +414,7 @@ pub enum MapChain<K,V> {
// get the map from an env frame // get the map from an env frame
impl <K: Eq + Hash + IterBytes ,V: Copy> MapChain<K,V>{ impl <K: Eq + Hash + IterBytes, V> MapChain<K,V>{
// Constructor. I don't think we need a zero-arg one. // Constructor. I don't think we need a zero-arg one.
fn new(init: ~HashMap<K,@V>) -> @mut MapChain<K,V> { fn new(init: ~HashMap<K,@V>) -> @mut MapChain<K,V> {

View file

@ -693,7 +693,7 @@ pub fn inject_std_macros(parse_sess: @mut parse::ParseSess,
cfg: ast::crate_cfg, c: &crate) -> @crate { cfg: ast::crate_cfg, c: &crate) -> @crate {
let sm = match parse_item_from_source_str(@"<std-macros>", let sm = match parse_item_from_source_str(@"<std-macros>",
std_macros(), std_macros(),
copy cfg, cfg.clone(),
~[], ~[],
parse_sess) { parse_sess) {
Some(item) => item, Some(item) => item,
@ -708,7 +708,7 @@ pub fn inject_std_macros(parse_sess: @mut parse::ParseSess,
ast::_mod { ast::_mod {
items: items, items: items,
// FIXME #2543: Bad copy. // FIXME #2543: Bad copy.
.. copy *modd .. (*modd).clone()
} }
}, },
.. *default_ast_fold() .. *default_ast_fold()

View file

@ -473,10 +473,10 @@ impl Parser {
// parse a sequence bracketed by '<' and '>', stopping // parse a sequence bracketed by '<' and '>', stopping
// before the '>'. // before the '>'.
pub fn parse_seq_to_before_gt<T: Copy>(&self, pub fn parse_seq_to_before_gt<T>(&self,
sep: Option<token::Token>, sep: Option<token::Token>,
f: &fn(&Parser) -> T) f: &fn(&Parser) -> T)
-> OptVec<T> { -> OptVec<T> {
let mut first = true; let mut first = true;
let mut v = opt_vec::Empty; let mut v = opt_vec::Empty;
while *self.token != token::GT while *self.token != token::GT
@ -493,10 +493,10 @@ impl Parser {
return v; return v;
} }
pub fn parse_seq_to_gt<T: Copy>(&self, pub fn parse_seq_to_gt<T>(&self,
sep: Option<token::Token>, sep: Option<token::Token>,
f: &fn(&Parser) -> T) f: &fn(&Parser) -> T)
-> OptVec<T> { -> OptVec<T> {
let v = self.parse_seq_to_before_gt(sep, f); let v = self.parse_seq_to_before_gt(sep, f);
self.expect_gt(); self.expect_gt();
return v; return v;
@ -505,11 +505,11 @@ impl Parser {
// parse a sequence, including the closing delimiter. The function // parse a sequence, including the closing delimiter. The function
// f must consume tokens until reaching the next separator or // f must consume tokens until reaching the next separator or
// closing bracket. // closing bracket.
pub fn parse_seq_to_end<T: Copy>(&self, pub fn parse_seq_to_end<T>(&self,
ket: &token::Token, ket: &token::Token,
sep: SeqSep, sep: SeqSep,
f: &fn(&Parser) -> T) f: &fn(&Parser) -> T)
-> ~[T] { -> ~[T] {
let val = self.parse_seq_to_before_end(ket, sep, f); let val = self.parse_seq_to_before_end(ket, sep, f);
self.bump(); self.bump();
val val
@ -518,11 +518,11 @@ impl Parser {
// parse a sequence, not including the closing delimiter. The function // parse a sequence, not including the closing delimiter. The function
// f must consume tokens until reaching the next separator or // f must consume tokens until reaching the next separator or
// closing bracket. // closing bracket.
pub fn parse_seq_to_before_end<T: Copy>(&self, pub fn parse_seq_to_before_end<T>(&self,
ket: &token::Token, ket: &token::Token,
sep: SeqSep, sep: SeqSep,
f: &fn(&Parser) -> T) f: &fn(&Parser) -> T)
-> ~[T] { -> ~[T] {
let mut first: bool = true; let mut first: bool = true;
let mut v: ~[T] = ~[]; let mut v: ~[T] = ~[];
while *self.token != *ket { while *self.token != *ket {
@ -542,12 +542,12 @@ impl Parser {
// parse a sequence, including the closing delimiter. The function // parse a sequence, including the closing delimiter. The function
// f must consume tokens until reaching the next separator or // f must consume tokens until reaching the next separator or
// closing bracket. // closing bracket.
pub fn parse_unspanned_seq<T: Copy>(&self, pub fn parse_unspanned_seq<T>(&self,
bra: &token::Token, bra: &token::Token,
ket: &token::Token, ket: &token::Token,
sep: SeqSep, sep: SeqSep,
f: &fn(&Parser) -> T) f: &fn(&Parser) -> T)
-> ~[T] { -> ~[T] {
self.expect(bra); self.expect(bra);
let result = self.parse_seq_to_before_end(ket, sep, f); let result = self.parse_seq_to_before_end(ket, sep, f);
self.bump(); self.bump();
@ -556,12 +556,12 @@ impl Parser {
// NB: Do not use this function unless you actually plan to place the // NB: Do not use this function unless you actually plan to place the
// spanned list in the AST. // spanned list in the AST.
pub fn parse_seq<T: Copy>(&self, pub fn parse_seq<T>(&self,
bra: &token::Token, bra: &token::Token,
ket: &token::Token, ket: &token::Token,
sep: SeqSep, sep: SeqSep,
f: &fn(&Parser) -> T) f: &fn(&Parser) -> T)
-> spanned<~[T]> { -> spanned<~[T]> {
let lo = self.span.lo; let lo = self.span.lo;
self.expect(bra); self.expect(bra);
let result = self.parse_seq_to_before_end(ket, sep, f); let result = self.parse_seq_to_before_end(ket, sep, f);

View file

@ -35,7 +35,7 @@ impl read for bool {
} }
} }
pub fn read<T:read + Copy>(s: ~str) -> T { pub fn read<T:read>(s: ~str) -> T {
match read::readMaybe(s) { match read::readMaybe(s) {
Some(x) => x, Some(x) => x,
_ => fail!("read failed!") _ => fail!("read failed!")

View file

@ -34,8 +34,8 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
return (xx as float) * 100f / (yy as float); return (xx as float) * 100f / (yy as float);
} }
fn le_by_val<TT:Copy + Clone, fn le_by_val<TT:Clone,
UU:Copy + Clone + Ord>( UU:Clone + Ord>(
kv0: &(TT,UU), kv0: &(TT,UU),
kv1: &(TT,UU)) kv1: &(TT,UU))
-> bool { -> bool {
@ -44,8 +44,8 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
return v0 >= v1; return v0 >= v1;
} }
fn le_by_key<TT:Copy + Clone + Ord, fn le_by_key<TT:Clone + Ord,
UU:Copy + Clone>( UU:Clone>(
kv0: &(TT,UU), kv0: &(TT,UU),
kv1: &(TT,UU)) kv1: &(TT,UU))
-> bool { -> bool {
@ -55,10 +55,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
} }
// sort by key, then by value // sort by key, then by value
fn sortKV<TT:Copy + Clone + Ord, fn sortKV<TT:Clone + Ord, UU:Clone + Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
UU:Copy + Clone + Ord>(
orig: ~[(TT,UU)])
-> ~[(TT,UU)] {
return sort::merge_sort(sort::merge_sort(orig, le_by_key), le_by_val); return sort::merge_sort(sort::merge_sort(orig, le_by_key), le_by_val);
} }

View file

@ -9,15 +9,15 @@
// except according to those terms. // except according to those terms.
fn foo<T>() { fn foo<T>() {
1u.bar::<T>(); //~ ERROR: does not fulfill `Copy` 1u.bar::<T>(); //~ ERROR: does not fulfill `Send`
} }
trait bar { trait bar {
fn bar<T:Copy>(&self); fn bar<T:Send>(&self);
} }
impl bar for uint { impl bar for uint {
fn bar<T:Copy>(&self) { fn bar<T:Send>(&self) {
} }
} }

View file

@ -9,11 +9,11 @@
// except according to those terms. // except according to those terms.
struct X { struct X {
field: @fn:Copy(), field: @fn:Send(),
} }
fn foo(blk: @fn:()) -> X { fn foo(blk: @fn:()) -> X {
return X { field: blk }; //~ ERROR expected bounds `Copy` but found no bounds return X { field: blk }; //~ ERROR expected bounds `Send` but found no bounds
} }
fn main() { fn main() {

View file

@ -1,26 +0,0 @@
// Copyright 2013 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.
use std::comm;
// If this were legal you could use it to copy captured noncopyables.
// Issue (#2828)
fn foo(blk: ~fn:Copy()) {
blk();
}
fn main() {
let (p,c) = comm::stream();
do foo {
c.send(()); //~ ERROR does not fulfill `Copy`
}
p.recv();
}

View file

@ -2,38 +2,16 @@
fn take_any(_: &fn:()) { fn take_any(_: &fn:()) {
} }
fn take_copyable(_: &fn:Copy()) {
}
fn take_copyable_owned(_: &fn:Copy+Send()) {
}
fn take_const_owned(_: &fn:Freeze+Send()) { fn take_const_owned(_: &fn:Freeze+Send()) {
} }
fn give_any(f: &fn:()) { fn give_any(f: &fn:()) {
take_any(f); take_any(f);
take_copyable(f); //~ ERROR expected bounds `Copy` but found no bounds
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found no bounds
}
fn give_copyable(f: &fn:Copy()) {
take_any(f);
take_copyable(f);
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found bounds `Copy`
} }
fn give_owned(f: &fn:Send()) { fn give_owned(f: &fn:Send()) {
take_any(f); take_any(f);
take_copyable(f); //~ ERROR expected bounds `Copy` but found bounds `Send` take_const_owned(f); //~ ERROR expected bounds `Freeze+Send` but found bounds `Send`
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found bounds `Send`
}
fn give_copyable_owned(f: &fn:Copy+Send()) {
take_any(f);
take_copyable(f);
take_copyable_owned(f);
take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Copy+Send`
} }
fn main() {} fn main() {}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn reproduce<T:Copy>(t: T) -> @fn() -> T { fn reproduce<T>(t: T) -> @fn() -> T {
let result: @fn() -> T = || t; let result: @fn() -> T = || t;
result result
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn mk_identity<T:Copy>() -> @fn(T) -> T { fn mk_identity<T>() -> @fn(T) -> T {
let result: @fn(t: T) -> T = |t| t; let result: @fn(t: T) -> T = |t| t;
result result
} }

View file

@ -37,7 +37,7 @@ fn main() {
let mut res = foo(x); let mut res = foo(x);
let mut v = ~[]; let mut v = ~[];
v = ~[(res)] + v; //~ instantiating a type parameter with an incompatible type `foo`, which does not fulfill `Copy` v = ~[(res)] + v; //~ instantiating a type parameter with an incompatible type `foo`, which does not fulfill `Clone`
assert_eq!(v.len(), 2); assert_eq!(v.len(), 2);
} }

View file

@ -12,7 +12,7 @@
// than the trait method it's implementing // than the trait method it's implementing
trait A { trait A {
fn b<C:Copy,D>(x: C) -> C; fn b<C,D>(x: C) -> C;
} }
struct E { struct E {
@ -20,7 +20,7 @@ struct E {
} }
impl A for E { impl A for E {
fn b<F:Copy + Freeze,G>(_x: F) -> F { fail!() } //~ ERROR type parameter 0 requires `Freeze` fn b<F:Freeze,G>(_x: F) -> F { fail!() } //~ ERROR type parameter 0 requires `Freeze`
} }
fn main() {} fn main() {}

View file

@ -12,7 +12,7 @@
// an impl against a trait // an impl against a trait
trait A { trait A {
fn b<C:Copy,D>(&self, x: C) -> C; fn b<C:Clone,D>(&self, x: C) -> C;
} }
struct E { struct E {
@ -21,7 +21,7 @@ struct E {
impl A for E { impl A for E {
// n.b. The error message is awful -- see #3404 // n.b. The error message is awful -- see #3404
fn b<F:Copy,G>(&self, _x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type fn b<F:Clone,G>(&self, _x: G) -> G { fail!() } //~ ERROR method `b` has an incompatible type
} }
fn main() {} fn main() {}

View file

@ -10,11 +10,11 @@
trait repeat<A> { fn get(&self) -> A; } trait repeat<A> { fn get(&self) -> A; }
impl<A:Copy> repeat<A> for @A { impl<A:Clone> repeat<A> for @A {
fn get(&self) -> A { **self } fn get(&self) -> A { **self }
} }
fn repeater<A:Copy>(v: @A) -> @repeat<A> { fn repeater<A:Clone>(v: @A) -> @repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type // Note: owned kind is not necessary as A appears in the trait type
@v as @repeat<A> // No @v as @repeat<A> // No
} }

View file

@ -18,11 +18,11 @@ trait foo {
fn foo(&self, i: &'self int) -> int; fn foo(&self, i: &'self int) -> int;
} }
impl<T:Copy> foo for T { impl<T:Clone> foo for T {
fn foo(&self, i: &'self int) -> int {*i} fn foo(&self, i: &'self int) -> int {*i}
} }
fn to_foo<T:Copy>(t: T) { fn to_foo<T:Clone>(t: T) {
// This version is ok because, although T may contain borrowed // This version is ok because, although T may contain borrowed
// pointers, it never escapes the fn body. We know this because // pointers, it never escapes the fn body. We know this because
// the type of foo includes a region which will be resolved to // the type of foo includes a region which will be resolved to
@ -33,14 +33,14 @@ fn to_foo<T:Copy>(t: T) {
assert_eq!(x.foo(v), 3); assert_eq!(x.foo(v), 3);
} }
fn to_foo_2<T:Copy>(t: T) -> @foo { fn to_foo_2<T:Clone>(t: T) -> @foo {
// Not OK---T may contain borrowed ptrs and it is going to escape // Not OK---T may contain borrowed ptrs and it is going to escape
// as part of the returned foo value // as part of the returned foo value
struct F<T> { f: T } struct F<T> { f: T }
@F {f:t} as @foo //~ ERROR value may contain borrowed pointers; add `'static` bound @F {f:t} as @foo //~ ERROR value may contain borrowed pointers; add `'static` bound
} }
fn to_foo_3<T:Copy + 'static>(t: T) -> @foo { fn to_foo_3<T:Clone + 'static>(t: T) -> @foo {
// OK---T may escape as part of the returned foo value, but it is // OK---T may escape as part of the returned foo value, but it is
// owned and hence does not contain borrowed ptrs // owned and hence does not contain borrowed ptrs
struct F<T> { f: T } struct F<T> { f: T }

View file

@ -10,13 +10,13 @@
trait foo { fn foo(&self); } trait foo { fn foo(&self); }
fn to_foo<T:Copy + foo>(t: T) -> @foo { fn to_foo<T:Clone + foo>(t: T) -> @foo {
@t as @foo @t as @foo
//~^ ERROR value may contain borrowed pointers; add `'static` bound //~^ ERROR value may contain borrowed pointers; add `'static` bound
//~^^ ERROR cannot pack type //~^^ ERROR cannot pack type
} }
fn to_foo2<T:Copy + foo + 'static>(t: T) -> @foo { fn to_foo2<T:Clone + foo + 'static>(t: T) -> @foo {
@t as @foo @t as @foo
} }

View file

@ -14,11 +14,11 @@ trait Foo {
fn a(_x: ~Foo:Send) { fn a(_x: ~Foo:Send) {
} }
fn b(_x: ~Foo:Send+Copy) { fn b(_x: ~Foo:Send+Clone) {
} }
fn c(x: ~Foo:Freeze+Send) { fn c(x: ~Foo:Freeze+Send) {
b(x); //~ ERROR expected bounds `Copy+Send` b(x); //~ ERROR expected bounds `Clone+Send`
} }
fn d(x: ~Foo:) { fn d(x: ~Foo:) {

View file

@ -16,7 +16,7 @@
struct Pair<T, U> { a: T, b: U } struct Pair<T, U> { a: T, b: U }
struct Triple { x: int, y: int, z: int } struct Triple { x: int, y: int, z: int }
fn f<T:Copy,U:Copy>(x: T, y: U) -> Pair<T, U> { return Pair {a: x, b: y}; } fn f<T,U>(x: T, y: U) -> Pair<T, U> { return Pair {a: x, b: y}; }
pub fn main() { pub fn main() {
info!("%?", f(Triple {x: 3, y: 4, z: 5}, 4).a.x); info!("%?", f(Triple {x: 3, y: 4, z: 5}, 4).a.x);

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn f<T:Copy>(x: ~[T]) -> T { return x[0]; } fn f<T>(x: ~[T]) -> T { return x[0]; }
fn g(act: &fn(~[int]) -> int) -> int { return act(~[1, 2, 3]); } fn g(act: &fn(~[int]) -> int) -> int { return act(~[1, 2, 3]); }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn clamp<T:Copy + Ord + Signed>(x: T, mn: T, mx: T) -> T { fn clamp<T:Ord + Signed>(x: T, mn: T, mx: T) -> T {
cond!( cond!(
(x > mx) { return mx; } (x > mx) { return mx; }
(x < mn) { return mn; } (x < mn) { return mn; }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn clamp<T:Copy + Ord + Signed>(x: T, mn: T, mx: T) -> T { fn clamp<T:Ord + Signed>(x: T, mn: T, mx: T) -> T {
cond!( cond!(
(x > mx) { mx } (x > mx) { mx }
(x < mn) { mn } (x < mn) { mn }

View file

@ -12,7 +12,7 @@
// are const. // are const.
fn foo<T:Copy + Freeze>(x: T) -> T { x } fn foo<T:Freeze>(x: T) -> T { x }
struct F { field: int } struct F { field: int }

View file

@ -13,7 +13,7 @@
// -*- rust -*- // -*- rust -*-
type compare<T> = @fn(~T, ~T) -> bool; type compare<T> = @fn(~T, ~T) -> bool;
fn test_generic<T:Copy+Clone>(expected: ~T, eq: compare<T>) { fn test_generic<T:Clone>(expected: ~T, eq: compare<T>) {
let actual: ~T = { expected.clone() }; let actual: ~T = { expected.clone() };
assert!((eq(expected, actual))); assert!((eq(expected, actual)));
} }

View file

@ -19,7 +19,7 @@ fn test_vec() {
} }
fn test_generic() { fn test_generic() {
fn f<T:Copy>(t: T) -> T { t } fn f<T>(t: T) -> T { t }
assert_eq!(f(10), 10); assert_eq!(f(10), 10);
} }

View file

@ -13,7 +13,7 @@
// -*- rust -*- // -*- rust -*-
type compare<T> = @fn(~T, ~T) -> bool; type compare<T> = @fn(~T, ~T) -> bool;
fn test_generic<T:Copy+Clone>(expected: ~T, eq: compare<T>) { fn test_generic<T:Clone>(expected: ~T, eq: compare<T>) {
let actual: ~T = match true { let actual: ~T = match true {
true => { expected.clone() }, true => { expected.clone() },
_ => fail!("wat") _ => fail!("wat")

View file

@ -13,7 +13,7 @@
type compare<T> = @fn(T, T) -> bool; type compare<T> = @fn(T, T) -> bool;
fn test_generic<T:Copy+Clone>(expected: T, eq: compare<T>) { fn test_generic<T:Clone>(expected: T, eq: compare<T>) {
let actual: T = match true { let actual: T = match true {
true => expected.clone(), true => expected.clone(),
_ => fail!("wat") _ => fail!("wat")

View file

@ -10,7 +10,7 @@
fn id<T:Copy>(t: T) -> T { return t; } fn id<T>(t: T) -> T { return t; }
pub fn main() { pub fn main() {
let expected = @100; let expected = @100;

View file

@ -10,7 +10,7 @@
fn id<T:Copy + Send>(t: T) -> T { return t; } fn id<T:Send>(t: T) -> T { return t; }
pub fn main() { pub fn main() {
let expected = ~100; let expected = ~100;

View file

@ -10,7 +10,7 @@
fn box<T:Copy>(x: Box<T>) -> @Box<T> { return @x; } fn box<T>(x: Box<T>) -> @Box<T> { return @x; }
struct Box<T> {x: T, y: T, z: T} struct Box<T> {x: T, y: T, z: T}

View file

@ -11,6 +11,6 @@
struct Pair { x: @int, y: @int } struct Pair { x: @int, y: @int }
fn f<T:Copy>(t: T) { let t1: T = t; } fn f<T>(t: T) { let t1: T = t; }
pub fn main() { let x = Pair {x: @10, y: @12}; f(x); } pub fn main() { let x = Pair {x: @10, y: @12}; f(x); }

View file

@ -12,7 +12,7 @@
struct Recbox<T> {x: @T} struct Recbox<T> {x: @T}
fn reclift<T:Copy>(t: T) -> Recbox<T> { return Recbox {x: @t}; } fn reclift<T>(t: T) -> Recbox<T> { return Recbox {x: @t}; }
pub fn main() { pub fn main() {
let foo: int = 17; let foo: int = 17;

View file

@ -10,7 +10,7 @@
struct Recbox<T> {x: ~T} struct Recbox<T> {x: ~T}
fn reclift<T:Copy>(t: T) -> Recbox<T> { return Recbox {x: ~t}; } fn reclift<T>(t: T) -> Recbox<T> { return Recbox {x: ~t}; }
pub fn main() { pub fn main() {
let foo: int = 17; let foo: int = 17;

View file

@ -14,6 +14,6 @@
// -*- rust -*- // -*- rust -*-
// Issue #45: infer type parameters in function applications // Issue #45: infer type parameters in function applications
fn id<T:Copy>(x: T) -> T { return x; } fn id<T>(x: T) -> T { return x; }
pub fn main() { let x: int = 42; let y: int = id(x); assert!((x == y)); } pub fn main() { let x: int = 42; let y: int = id(x); assert!((x == y)); }

View file

@ -9,6 +9,6 @@
// except according to those terms. // except according to those terms.
fn f<T:Copy>(x: ~T) -> ~T { return x; } fn f<T>(x: ~T) -> ~T { return x; }
pub fn main() { let x = f(~3); info!(*x); } pub fn main() { let x = f(~3); info!(*x); }

View file

@ -12,7 +12,7 @@
// -*- rust -*- // -*- rust -*-
fn id<T:Copy>(x: T) -> T { return x; } fn id<T>(x: T) -> T { return x; }
struct Triple {x: int, y: int, z: int} struct Triple {x: int, y: int, z: int}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn get_third<T:Copy>(t: (T, T, T)) -> T { let (_, _, x) = t; return x; } fn get_third<T>(t: (T, T, T)) -> T { let (_, _, x) = t; return x; }
pub fn main() { pub fn main() {
info!(get_third((1, 2, 3))); info!(get_third((1, 2, 3)));

View file

@ -10,7 +10,7 @@
struct Triple<T> { x: T, y: T, z: T } struct Triple<T> { x: T, y: T, z: T }
fn box<T:Copy>(x: Triple<T>) -> ~Triple<T> { return ~x; } fn box<T>(x: Triple<T>) -> ~Triple<T> { return ~x; }
pub fn main() { pub fn main() {
let x: ~Triple<int> = box::<int>(Triple{x: 1, y: 2, z: 3}); let x: ~Triple<int> = box::<int>(Triple{x: 1, y: 2, z: 3});

View file

@ -8,25 +8,25 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait clam<A:Copy> { trait clam<A> {
fn chowder(&self, y: A); fn chowder(&self, y: A);
} }
struct foo<A> { struct foo<A> {
x: A, x: A,
} }
impl<A:Copy> clam<A> for foo<A> { impl<A> clam<A> for foo<A> {
fn chowder(&self, y: A) { fn chowder(&self, y: A) {
} }
} }
fn foo<A:Copy>(b: A) -> foo<A> { fn foo<A>(b: A) -> foo<A> {
foo { foo {
x: b x: b
} }
} }
fn f<A:Copy>(x: @clam<A>, a: A) { fn f<A>(x: @clam<A>, a: A) {
x.chowder(a); x.chowder(a);
} }

View file

@ -8,18 +8,18 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait clam<A:Copy> { } trait clam<A> { }
struct foo<A> { struct foo<A> {
x: A, x: A,
} }
impl<A:Copy> foo<A> { impl<A> foo<A> {
pub fn bar<B,C:clam<A>>(&self, c: C) -> B { pub fn bar<B,C:clam<A>>(&self, c: C) -> B {
fail!(); fail!();
} }
} }
fn foo<A:Copy>(b: A) -> foo<A> { fn foo<A>(b: A) -> foo<A> {
foo { foo {
x: b x: b
} }

View file

@ -12,18 +12,18 @@ struct c1<T> {
x: T, x: T,
} }
impl<T:Copy> c1<T> { impl<T> c1<T> {
pub fn f1(&self, x: int) { pub fn f1(&self, x: int) {
} }
} }
fn c1<T:Copy>(x: T) -> c1<T> { fn c1<T>(x: T) -> c1<T> {
c1 { c1 {
x: x x: x
} }
} }
impl<T:Copy> c1<T> { impl<T> c1<T> {
pub fn f2(&self, x: int) { pub fn f2(&self, x: int) {
} }
} }

View file

@ -12,17 +12,17 @@ struct c1<T> {
x: T, x: T,
} }
impl<T:Copy> c1<T> { impl<T> c1<T> {
pub fn f1(&self, x: T) {} pub fn f1(&self, x: T) {}
} }
fn c1<T:Copy>(x: T) -> c1<T> { fn c1<T>(x: T) -> c1<T> {
c1 { c1 {
x: x x: x
} }
} }
impl<T:Copy> c1<T> { impl<T> c1<T> {
pub fn f2(&self, x: T) {} pub fn f2(&self, x: T) {}
} }

View file

@ -18,7 +18,7 @@ fn C(x: uint) -> C {
} }
} }
fn f<T:Copy>(_x: T) { fn f<T>(_x: T) {
} }
#[deny(non_implicitly_copyable_typarams)] #[deny(non_implicitly_copyable_typarams)]

View file

@ -12,7 +12,7 @@
// than the traits require. // than the traits require.
trait A { trait A {
fn b<C:Copy + Freeze,D>(x: C) -> C; fn b<C:Freeze,D>(x: C) -> C;
} }
struct E { struct E {
@ -20,7 +20,7 @@ struct E {
} }
impl A for E { impl A for E {
fn b<F:Copy,G>(_x: F) -> F { fail!() } //~ ERROR in method `b`, type parameter 0 has 1 bound, but fn b<F,G>(_x: F) -> F { fail!() } //~ ERROR in method `b`, type parameter 0 has 1 bound, but
} }
fn main() {} fn main() {}

View file

@ -8,12 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn Matrix4<T:Copy>(m11: T, m12: T, m13: T, m14: T, fn Matrix4<T>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T, m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T, m31: T, m32: T, m33: T, m34: T,
m41: T, m42: T, m43: T, m44: T) m41: T, m42: T, m43: T, m44: T)
-> Matrix4<T> { -> Matrix4<T> {
Matrix4 { Matrix4 {
m11: m11, m12: m12, m13: m13, m14: m14, m11: m11, m12: m12, m13: m13, m14: m14,
m21: m21, m22: m22, m23: m23, m24: m24, m21: m21, m22: m22, m23: m23, m24: m24,

View file

@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn quux<T:Copy>(x: T) -> T { let f = id::<T>; return f(x); } fn quux<T>(x: T) -> T { let f = id::<T>; return f(x); }
fn id<T:Copy>(x: T) -> T { return x; } fn id<T>(x: T) -> T { return x; }
pub fn main() { assert!((quux(10) == 10)); } pub fn main() { assert!((quux(10) == 10)); }

View file

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

View file

@ -13,11 +13,11 @@
use std::int; use std::int;
trait vec_monad<A> { trait vec_monad<A> {
fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B]; fn bind<B>(&self, f: &fn(&A) -> ~[B]) -> ~[B];
} }
impl<A> vec_monad<A> for ~[A] { impl<A> vec_monad<A> for ~[A] {
fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B] { fn bind<B>(&self, f: &fn(&A) -> ~[B]) -> ~[B] {
let mut r = ~[]; let mut r = ~[];
for self.iter().advance |elt| { for self.iter().advance |elt| {
r.push_all_move(f(elt)); r.push_all_move(f(elt));

View file

@ -25,7 +25,7 @@ impl Serializable for int {
struct F<A> { a: A } struct F<A> { a: A }
impl<A:Copy + Serializable> Serializable for F<A> { impl<A:Serializable> Serializable for F<A> {
fn serialize<S:Serializer>(&self, s: S) { fn serialize<S:Serializer>(&self, s: S) {
self.a.serialize(s); self.a.serialize(s);
} }

View file

@ -14,15 +14,15 @@ extern mod extra;
use extra::list::*; use extra::list::*;
fn pure_length_go<T:Copy>(ls: @List<T>, acc: uint) -> uint { fn pure_length_go<T>(ls: @List<T>, acc: uint) -> uint {
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } } match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
} }
fn pure_length<T:Copy>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) } fn pure_length<T>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
fn nonempty_list<T:Copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u } fn nonempty_list<T>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
fn safe_head<T:Copy>(ls: @List<T>) -> T { fn safe_head<T>(ls: @List<T>) -> T {
assert!(!is_empty(ls)); assert!(!is_empty(ls));
return head(ls); return head(ls);
} }

View file

@ -23,7 +23,7 @@ fn iter<T>(v: ~[T], it: &fn(&T) -> bool) -> bool {
return true; return true;
} }
fn find_pos<T:Eq + Copy + Clone>(n: T, h: ~[T]) -> Option<uint> { fn find_pos<T:Eq + Clone>(n: T, h: ~[T]) -> Option<uint> {
let mut i = 0u; let mut i = 0u;
for iter(h.clone()) |e| { for iter(h.clone()) |e| {
if *e == n { return Some(i); } if *e == n { return Some(i); }

View file

@ -12,6 +12,6 @@
enum option<T> { none, some(T), } enum option<T> { none, some(T), }
fn f<T:Copy>() -> option<T> { return none; } fn f<T>() -> option<T> { return none; }
pub fn main() { f::<int>(); } pub fn main() { f::<int>(); }

View file

@ -43,13 +43,13 @@ impl uint_utils for uint {
trait vec_utils<T> { trait vec_utils<T> {
fn length_(&self, ) -> uint; fn length_(&self, ) -> uint;
fn iter_(&self, f: &fn(&T)); fn iter_(&self, f: &fn(&T));
fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U]; fn map_<U>(&self, f: &fn(&T) -> U) -> ~[U];
} }
impl<T> vec_utils<T> for ~[T] { impl<T> vec_utils<T> for ~[T] {
fn length_(&self) -> uint { self.len() } fn length_(&self) -> uint { self.len() }
fn iter_(&self, f: &fn(&T)) { for self.iter().advance |x| { f(x); } } fn iter_(&self, f: &fn(&T)) { for self.iter().advance |x| { f(x); } }
fn map_<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] { fn map_<U>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r = ~[]; let mut r = ~[];
for self.iter().advance |elt| { for self.iter().advance |elt| {
r.push(f(elt)); r.push(f(elt));

View file

@ -24,7 +24,7 @@ struct t_rec<A,B> {
tB: a_tag<A,B> tB: a_tag<A,B>
} }
fn mk_rec<A:Copy,B:Copy>(a: A, b: B) -> t_rec<A,B> { fn mk_rec<A,B>(a: A, b: B) -> t_rec<A,B> {
return t_rec{ chA:0u8, tA:varA(a), chB:1u8, tB:varB(b) }; return t_rec{ chA:0u8, tA:varA(a), chB:1u8, tB:varB(b) };
} }

View file

@ -21,7 +21,7 @@ fn c(x: ~Foo:Freeze+Send) {
a(x); a(x);
} }
fn d(x: ~Foo:Send+Copy) { fn d(x: ~Foo:Send) {
b(x); b(x);
} }

View file

@ -26,10 +26,10 @@ impl to_str for () {
} }
trait map<T> { trait map<T> {
fn map<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U]; fn map<U>(&self, f: &fn(&T) -> U) -> ~[U];
} }
impl<T> map<T> for ~[T] { impl<T> map<T> for ~[T] {
fn map<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] { fn map<U>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r = ~[]; let mut r = ~[];
// FIXME: #7355 generates bad code with Iterator // FIXME: #7355 generates bad code with Iterator
for std::uint::range(0, self.len()) |i| { for std::uint::range(0, self.len()) |i| {

View file

@ -14,7 +14,7 @@
extern mod trait_inheritance_overloading_xc; extern mod trait_inheritance_overloading_xc;
use trait_inheritance_overloading_xc::{MyNum, MyInt}; use trait_inheritance_overloading_xc::{MyNum, MyInt};
fn f<T:Copy + MyNum>(x: T, y: T) -> (T, T, T) { fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
return (x + y, x - y, x * y); return (x + y, x - y, x * y);
} }

View file

@ -33,7 +33,7 @@ impl Eq for MyInt {
impl MyNum for MyInt; impl MyNum for MyInt;
fn f<T:Copy + MyNum>(x: T, y: T) -> (T, T, T) { fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
return (x + y, x - y, x * y); return (x + y, x - y, x * y);
} }

View file

@ -11,7 +11,7 @@
// xfail-fast // xfail-fast
fn p_foo<T>(pinned: T) { } fn p_foo<T>(pinned: T) { }
fn s_foo<T:Copy>(shared: T) { } fn s_foo<T>(shared: T) { }
fn u_foo<T:Send>(unique: T) { } fn u_foo<T:Send>(unique: T) { }
struct r { struct r {

View file

@ -20,7 +20,7 @@ struct Pointy {
d : ~fn() -> uint, d : ~fn() -> uint,
} }
fn make_uniq_closure<A:Send + Copy>(a: A) -> ~fn() -> uint { fn make_uniq_closure<A:Send>(a: A) -> ~fn() -> uint {
let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint; let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint;
result result
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn f<T:Copy>(t: T) -> T { fn f<T>(t: T) -> T {
let t1 = t; let t1 = t;
t1 t1
} }

View file

@ -10,7 +10,7 @@
// Issue #976 // Issue #976
fn f<T:Copy>(x: ~T) { fn f<T>(x: ~T) {
let _x2 = x; let _x2 = x;
} }
pub fn main() { } pub fn main() { }

View file

@ -30,11 +30,11 @@ fn sendable() {
fn copyable() { fn copyable() {
fn f<T:Copy + Eq>(i: T, j: T) { fn f<T:Eq>(i: T, j: T) {
assert_eq!(i, j); assert_eq!(i, j);
} }
fn g<T:Copy + Eq>(i: T, j: T) { fn g<T:Eq>(i: T, j: T) {
assert!(i != j); assert!(i != j);
} }

View file

@ -1,8 +1,7 @@
fn foldl<T, U: Copy+Clone>( fn foldl<T,U:Clone>(values: &[T],
values: &[T], initial: U,
initial: U, function: &fn(partial: U, element: &T) -> U)
function: &fn(partial: U, element: &T) -> U -> U {
) -> U {
match values { match values {
[ref head, ..tail] => [ref head, ..tail] =>
foldl(tail, function(initial, head), function), foldl(tail, function(initial, head), function),
@ -10,11 +9,10 @@ fn foldl<T, U: Copy+Clone>(
} }
} }
fn foldr<T, U: Copy+Clone>( fn foldr<T,U:Clone>(values: &[T],
values: &[T], initial: U,
initial: U, function: &fn(element: &T, partial: U) -> U)
function: &fn(element: &T, partial: U) -> U -> U {
) -> U {
match values { match values {
[..head, ref tail] => [..head, ref tail] =>
foldr(head, function(tail, initial), function), foldr(head, function(tail, initial), function),