}
/// 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] {
vec::concat(map_slices(xs, || {
let f = fn_factory();
}
/// 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],
fn_factory: &fn() -> ~fn(uint, &A) -> B) -> ~[B] {
let slices = map_slices(xs, || {
}
}
-impl<
- S: Encoder,
- T: Encodable<S> + Copy
-> Encodable<S> for DList<T> {
+impl<S: Encoder, T: Encodable<S>> Encodable<S> for @mut DList<T> {
fn encode(&self, s: &mut S) {
do s.emit_seq(self.len()) |s| {
let mut i = 0;
* Has worst case O(n log n) performance, best case O(n), but
* 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);
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 end = slice.second();
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 a_len = a.len();
let mut a_ix = 0;
static INITIAL_TMP_STORAGE: uint = 128;
#[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();
if size < 2 {
return;
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 mut start = start;
assert!(start <= size);
}
}
-impl<T:Copy + Clone + Ord> MergeState<T> {
+impl<T:Clone + Ord> MergeState<T> {
fn push_run(&mut self, run_base: uint, run_len: uint) {
let tmp = RunState{base: run_base, len: run_len};
self.runs.push(tmp);
}
#[inline]
-fn shift_vec<T:Copy + Clone>(dest: &mut [T],
- s1: uint,
- s2: uint,
- len: uint) {
+fn shift_vec<T:Clone>(dest: &mut [T], s1: uint, s2: uint, len: uint) {
assert!(s1+len <= dest.len());
let tmp = dest.slice(s2, s2+len).to_owned();
* on the provided port in the allotted timeout period, then the result will
* be a `Some(T)`. If not, then `None` will be returned.
*/
-pub fn recv_timeout<T:Copy + Send>(iotask: &IoTask,
- msecs: uint,
- wait_po: &Port<T>)
- -> Option<T> {
+pub fn recv_timeout<T:Send>(iotask: &IoTask, msecs: uint, wait_po: &Port<T>)
+ -> Option<T> {
let (timeout_po, timeout_ch) = stream::<()>();
let mut timeout_po = timeout_po;
delayed_send(iotask, msecs, &timeout_ch, ());
}
}
-enum Action<'self> {
- Call(&'self fn:Copy(args: &[~str]) -> ValidUsage),
- CallMain(&'static str, &'self fn:Copy()),
+enum Action {
+ Call(extern "Rust" fn(args: &[~str]) -> ValidUsage),
+ CallMain(&'static str, extern "Rust" fn()),
}
enum UsageSource<'self> {
UsgStr(&'self str),
- UsgCall(&'self fn:Copy()),
+ UsgCall(extern "Rust" fn()),
}
struct Command<'self> {
cmd: &'self str,
- action: Action<'self>,
+ action: Action,
usage_line: &'self str,
usage_full: UsageSource<'self>,
}
//
// baz! should not use this definition unless foo is enabled.
crate = time(time_passes, ~"std macros injection", ||
- syntax::ext::expand::inject_std_macros(sess.parse_sess, copy cfg,
- crate));
+ syntax::ext::expand::inject_std_macros(sess.parse_sess,
+ cfg.clone(),
+ crate));
crate = time(time_passes, ~"configuration 1", ||
front::config::strip_unconfigured_items(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() }
}
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() }
}
} 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;
for filesearch.for_each_lib_search_path() |lib_search_path| {
debug!("searching %s", lib_search_path.to_str());
fn test_simplification() {
let ext_cx = mk_ctxt();
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 }
return alist {eq_fn: eq_int, data: ~[]};
}
).get());
let item_out = simplify_ast(&item_in);
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: ~[]};
}
).get());
// This is used to make the simple visitors used for the lint passes
// not traverse into subitems, since that is handled by the outer
// 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_item: |_i, (_e, _v)| { },
visit_fn: |fk, fd, b, s, id, (e, v)| {
fn store_type_uses(cx: Context, fn_id: def_id) -> @~[type_uses] {
let Context { uses, ccx } = cx;
- let uses = @copy *uses; // freeze
+ let uses = @(*uses).clone(); // freeze
ccx.type_use_cache.insert(fn_id, uses);
uses
}
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()
}
// through the `unpack` function. It there is no expected type or
// resolution is not possible (e.g., no constraints yet present), just
// returns `none`.
- fn unpack_expected<O:Copy>(fcx: @mut FnCtxt,
- expected: Option<ty::t>,
- unpack: &fn(&ty::sty) -> Option<O>)
- -> Option<O> {
+ fn unpack_expected<O>(fcx: @mut FnCtxt,
+ expected: Option<ty::t>,
+ unpack: &fn(&ty::sty) -> Option<O>)
+ -> Option<O> {
match expected {
Some(t) => {
match resolve_type(fcx.infcx(), t, force_tvar) {
use rustc::front::config;
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 = syntax::ext::expand::expand_crate(sess.parse_sess,
sess.opts.cfg.clone(),
== ~"impl-of-selectt-u-for-left-right");
assert!(pandoc_header_id("impl of Condition<'self, T, U>")
== ~"impl-of-conditionself-t-u");
- assert!(pandoc_header_id("impl of Condition<T: Copy + Clone>")
- == ~"impl-of-conditiont-copy-clone");
+ assert!(pandoc_header_id("impl of Condition<T: Clone>")
+ == ~"impl-of-conditiont-clone");
}
#[test]
#[test]
fn should_add_impl_bounds() {
- let doc = mk_doc(~"impl<T, U: Copy, V: Copy + Clone> Option<T, U, V> { }");
- assert!(doc.cratemod().impls()[0].bounds_str == Some(~"<T, U: Copy, V: Copy + Clone>"));
+ let doc = mk_doc(~"impl<T, U, V: Clone> Option<T, U, V> { }");
+ assert!(doc.cratemod().impls()[0].bounds_str == Some(~"<T, U, V: Clone>"));
}
#[test]
fail!("package database contains duplicate ID");
}
else {
- contents.push(copy *p);
+ contents.push((*p).clone());
}
false
};
leaving the original value in place. These types do not require
allocation to copy and do not have finalizers (i.e. they do not
contain owned boxes or implement `Drop`), so the compiler considers
-them cheap and safe to copy and automatically implements the `Copy`
-trait for them. For other types copies must be made explicitly,
-by convention implementing the `Clone` trait and calling the
-`clone` method.
+them cheap and safe to copy. For other types copies must be made
+explicitly, by convention implementing the `Clone` trait and calling
+the `clone` method.
*/
pub fn raise(&self, t: T) -> U {
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 trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U> {
unsafe {
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 };
Trap { cond: self, handler: h }
}
pub fn raise_default(&self, t: T, default: &fn() -> U) -> U {
unsafe {
- match local_data::pop(self.key) {
+ match local_data::pop(::cast::unsafe_copy(&self.key)) {
None => {
debug!("Condition.raise: found no handler");
default()
debug!("Condition.raise: found handler");
match handler.prev {
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 =
::cast::transmute(handler.handle);
let u = handle(t);
- local_data::set(self.key, handler);
+ local_data::set(::cast::unsafe_copy(&self.key), handler);
u
}
}
They cannot be implemented by user code, but are instead implemented
by the compiler automatically for the types to which they apply.
-The 3 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`.
+The 2 kinds are
* Send - owned types and types containing owned types. These types
may be transferred across task boundaries.
* 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)];
#[cfg(not(stage0))]
pub type Key<T> = &'static KeyValue<T>;
#[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 }
use ops::{Add, Sub, Mul, Div, Rem, Neg};
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
use option::Option;
-use kinds::Copy;
pub mod strconv;
/// - If code written to use this function doesn't care about it, it's
/// 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 _1: T = One::one();
use ops::{Add, Sub, Mul, Div, Rem, Neg};
use option::{None, Option, Some};
use char;
+use str::{StrSlice};
use str;
-use str::StrSlice;
-use kinds::Copy;
use vec::{CopyableVector, ImmutableVector, MutableVector};
use vec::OwnedVector;
use num::{NumCast, Zero, One, cast, pow_with_uint, Integer};
* - Fails if `radix` > 18 and `special == true` due to conflict
* 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>+
NumStrConv+Clone>(
buf: &[u8], radix: uint, negative: bool, fractional: bool,
* `from_str_bytes_common()`, for details see there.
*/
#[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>(
buf: &str, radix: uint, negative: bool, fractional: bool,
special: bool, exponent: ExponentFormat, empty_zero: bool,
// Reexported core operators
pub use either::{Either, Left, Right};
-pub use kinds::{Copy, Sized};
+pub use kinds::Sized;
pub use kinds::{Freeze, Send};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
* }
* ~~~
*/
- 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
fn choose_option<T:Clone>(&mut self, values: &[T]) -> Option<T>;
/**
* }
* ~~~
*/
- 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
* the sum of the weights is 0
* }
* ~~~
*/
- 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
*
}
/// 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()
}
* Choose an item respecting the relative weights, failing if the sum of
* 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()
}
}
/// 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();
self.shuffle_mut(m);
m
use local_data;
use prelude::*;
use ptr;
+use sys;
use task::rt;
use util;
}
}
-fn key_to_key_value<T: 'static>(key: local_data::Key<T>) -> *libc::c_void {
- unsafe { cast::transmute(key) }
+unsafe fn key_to_key_value<T: 'static>(key: local_data::Key<T>) -> *libc::c_void {
+ let pair: sys::Closure = cast::transmute_copy(&key);
+ return pair.code as *libc::c_void;
}
pub unsafe fn local_pop<T: 'static>(handle: Handle,
impl<T> TrieNode<T> {
#[inline]
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,
children: [Nothing, Nothing, Nothing, Nothing,
Nothing, Nothing, Nothing, Nothing,
#[allow(missing_doc)];
use clone::Clone;
-use kinds::Copy;
use vec;
use vec::ImmutableVector;
use iterator::IteratorUtil;
}
impl<'self,
- A:Copy + Clone,
- B:Copy + Clone>
+ A:Clone,
+ B:Clone>
ExtendedTupleOps<A,B> for
(&'self [A], &'self [B]) {
#[inline]
}
}
-impl<A:Copy + Clone,
- B:Copy + Clone>
- ExtendedTupleOps<A,B> for
- (~[A], ~[B]) {
+impl<A:Clone, B:Clone> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
#[inline]
fn zip(&self) -> ~[(A, B)] {
match *self {
use parse::token;
use visit;
+use std::cast::unsafe_copy;
+use std::cast;
use std::hashmap::HashMap;
use std::int;
+use std::local_data;
use std::num;
use std::option;
-use std::local_data;
pub fn path_name_i(idents: &[ident]) -> ~str {
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
// 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.
fn new(init: ~HashMap<K,@V>) -> @mut MapChain<K,V> {
cfg: ast::crate_cfg, c: &crate) -> @crate {
let sm = match parse_item_from_source_str(@"<std-macros>",
std_macros(),
- copy cfg,
+ cfg.clone(),
~[],
parse_sess) {
Some(item) => item,
ast::_mod {
items: items,
// FIXME #2543: Bad copy.
- .. copy *modd
+ .. (*modd).clone()
}
},
.. *default_ast_fold()
// parse a sequence bracketed by '<' and '>', stopping
// before the '>'.
- pub fn parse_seq_to_before_gt<T: Copy>(&self,
- sep: Option<token::Token>,
- f: &fn(&Parser) -> T)
- -> OptVec<T> {
+ pub fn parse_seq_to_before_gt<T>(&self,
+ sep: Option<token::Token>,
+ f: &fn(&Parser) -> T)
+ -> OptVec<T> {
let mut first = true;
let mut v = opt_vec::Empty;
while *self.token != token::GT
return v;
}
- pub fn parse_seq_to_gt<T: Copy>(&self,
- sep: Option<token::Token>,
- f: &fn(&Parser) -> T)
- -> OptVec<T> {
+ pub fn parse_seq_to_gt<T>(&self,
+ sep: Option<token::Token>,
+ f: &fn(&Parser) -> T)
+ -> OptVec<T> {
let v = self.parse_seq_to_before_gt(sep, f);
self.expect_gt();
return v;
// parse a sequence, including the closing delimiter. The function
// f must consume tokens until reaching the next separator or
// closing bracket.
- pub fn parse_seq_to_end<T: Copy>(&self,
- ket: &token::Token,
- sep: SeqSep,
- f: &fn(&Parser) -> T)
- -> ~[T] {
+ pub fn parse_seq_to_end<T>(&self,
+ ket: &token::Token,
+ sep: SeqSep,
+ f: &fn(&Parser) -> T)
+ -> ~[T] {
let val = self.parse_seq_to_before_end(ket, sep, f);
self.bump();
val
// parse a sequence, not including the closing delimiter. The function
// f must consume tokens until reaching the next separator or
// closing bracket.
- pub fn parse_seq_to_before_end<T: Copy>(&self,
- ket: &token::Token,
- sep: SeqSep,
- f: &fn(&Parser) -> T)
- -> ~[T] {
+ pub fn parse_seq_to_before_end<T>(&self,
+ ket: &token::Token,
+ sep: SeqSep,
+ f: &fn(&Parser) -> T)
+ -> ~[T] {
let mut first: bool = true;
let mut v: ~[T] = ~[];
while *self.token != *ket {
// parse a sequence, including the closing delimiter. The function
// f must consume tokens until reaching the next separator or
// closing bracket.
- pub fn parse_unspanned_seq<T: Copy>(&self,
- bra: &token::Token,
- ket: &token::Token,
- sep: SeqSep,
- f: &fn(&Parser) -> T)
- -> ~[T] {
+ pub fn parse_unspanned_seq<T>(&self,
+ bra: &token::Token,
+ ket: &token::Token,
+ sep: SeqSep,
+ f: &fn(&Parser) -> T)
+ -> ~[T] {
self.expect(bra);
let result = self.parse_seq_to_before_end(ket, sep, f);
self.bump();
// NB: Do not use this function unless you actually plan to place the
// spanned list in the AST.
- pub fn parse_seq<T: Copy>(&self,
- bra: &token::Token,
- ket: &token::Token,
- sep: SeqSep,
- f: &fn(&Parser) -> T)
- -> spanned<~[T]> {
+ pub fn parse_seq<T>(&self,
+ bra: &token::Token,
+ ket: &token::Token,
+ sep: SeqSep,
+ f: &fn(&Parser) -> T)
+ -> spanned<~[T]> {
let lo = self.span.lo;
self.expect(bra);
let result = self.parse_seq_to_before_end(ket, sep, f);
}
}
-pub fn read<T:read + Copy>(s: ~str) -> T {
+pub fn read<T:read>(s: ~str) -> T {
match read::readMaybe(s) {
Some(x) => x,
_ => fail!("read failed!")
return (xx as float) * 100f / (yy as float);
}
- fn le_by_val<TT:Copy + Clone,
- UU:Copy + Clone + Ord>(
+ fn le_by_val<TT:Clone,
+ UU:Clone + Ord>(
kv0: &(TT,UU),
kv1: &(TT,UU))
-> bool {
return v0 >= v1;
}
- fn le_by_key<TT:Copy + Clone + Ord,
- UU:Copy + Clone>(
+ fn le_by_key<TT:Clone + Ord,
+ UU:Clone>(
kv0: &(TT,UU),
kv1: &(TT,UU))
-> bool {
}
// sort by key, then by value
- fn sortKV<TT:Copy + Clone + Ord,
- UU:Copy + Clone + Ord>(
- orig: ~[(TT,UU)])
- -> ~[(TT,UU)] {
+ fn sortKV<TT:Clone + Ord, UU:Clone + Ord>(orig: ~[(TT,UU)]) -> ~[(TT,UU)] {
return sort::merge_sort(sort::merge_sort(orig, le_by_key), le_by_val);
}
// except according to those terms.
fn foo<T>() {
- 1u.bar::<T>(); //~ ERROR: does not fulfill `Copy`
+ 1u.bar::<T>(); //~ ERROR: does not fulfill `Send`
}
trait bar {
- fn bar<T:Copy>(&self);
+ fn bar<T:Send>(&self);
}
impl bar for uint {
- fn bar<T:Copy>(&self) {
+ fn bar<T:Send>(&self) {
}
}
// except according to those terms.
struct X {
- field: @fn:Copy(),
+ field: @fn:Send(),
}
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() {
+++ /dev/null
-// 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();
-}
fn take_any(_: &fn:()) {
}
-fn take_copyable(_: &fn:Copy()) {
-}
-
-fn take_copyable_owned(_: &fn:Copy+Send()) {
-}
-
fn take_const_owned(_: &fn:Freeze+Send()) {
}
fn give_any(f: &fn:()) {
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()) {
take_any(f);
- take_copyable(f); //~ ERROR expected bounds `Copy` 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`
+ take_const_owned(f); //~ ERROR expected bounds `Freeze+Send` but found bounds `Send`
}
fn main() {}
// option. This file may not be copied, modified, or distributed
// 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;
result
}
// option. This file may not be copied, modified, or distributed
// 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;
result
}
let mut res = foo(x);
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);
}
// than the trait method it's implementing
trait A {
- fn b<C:Copy,D>(x: C) -> C;
+ fn b<C,D>(x: C) -> C;
}
struct 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() {}
// an impl against a trait
trait A {
- fn b<C:Copy,D>(&self, x: C) -> C;
+ fn b<C:Clone,D>(&self, x: C) -> C;
}
struct E {
impl A for E {
// 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() {}
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 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
@v as @repeat<A> // No
}
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 to_foo<T:Copy>(t: T) {
+fn to_foo<T:Clone>(t: T) {
// This version is ok because, although T may contain borrowed
// pointers, it never escapes the fn body. We know this because
// the type of foo includes a region which will be resolved to
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
// as part of the returned foo value
struct F<T> { f: T }
@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
// owned and hence does not contain borrowed ptrs
struct F<T> { f: T }
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
//~^ ERROR value may contain borrowed pointers; add `'static` bound
//~^^ 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
}
fn a(_x: ~Foo:Send) {
}
-fn b(_x: ~Foo:Send+Copy) {
+fn b(_x: ~Foo:Send+Clone) {
}
fn c(x: ~Foo:Freeze+Send) {
- b(x); //~ ERROR expected bounds `Copy+Send`
+ b(x); //~ ERROR expected bounds `Clone+Send`
}
fn d(x: ~Foo:) {
struct Pair<T, U> { a: T, b: U }
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() {
info!("%?", f(Triple {x: 3, y: 4, z: 5}, 4).a.x);
// option. This file may not be copied, modified, or distributed
// 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]); }
// option. This file may not be copied, modified, or distributed
// 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!(
(x > mx) { return mx; }
(x < mn) { return mn; }
// option. This file may not be copied, modified, or distributed
// 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!(
(x > mx) { mx }
(x < mn) { mn }
// are const.
-fn foo<T:Copy + Freeze>(x: T) -> T { x }
+fn foo<T:Freeze>(x: T) -> T { x }
struct F { field: int }
// -*- rust -*-
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() };
assert!((eq(expected, actual)));
}
}
fn test_generic() {
- fn f<T:Copy>(t: T) -> T { t }
+ fn f<T>(t: T) -> T { t }
assert_eq!(f(10), 10);
}
// -*- rust -*-
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 {
true => { expected.clone() },
_ => fail!("wat")
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 {
true => expected.clone(),
_ => fail!("wat")
-fn id<T:Copy>(t: T) -> T { return t; }
+fn id<T>(t: T) -> T { return t; }
pub fn main() {
let expected = @100;
-fn id<T:Copy + Send>(t: T) -> T { return t; }
+fn id<T:Send>(t: T) -> T { return t; }
pub fn main() {
let expected = ~100;
-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 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); }
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() {
let foo: int = 17;
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() {
let foo: int = 17;
// -*- rust -*-
// 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)); }
// 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); }
// -*- 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}
// option. This file may not be copied, modified, or distributed
// 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() {
info!(get_third((1, 2, 3)));
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() {
let x: ~Triple<int> = box::<int>(Triple{x: 1, y: 2, z: 3});
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait clam<A:Copy> {
+trait clam<A> {
fn chowder(&self, y: A);
}
struct foo<A> {
x: A,
}
-impl<A:Copy> clam<A> for foo<A> {
+impl<A> clam<A> for foo<A> {
fn chowder(&self, y: A) {
}
}
-fn foo<A:Copy>(b: A) -> foo<A> {
+fn foo<A>(b: A) -> foo<A> {
foo {
x: b
}
}
-fn f<A:Copy>(x: @clam<A>, a: A) {
+fn f<A>(x: @clam<A>, a: A) {
x.chowder(a);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait clam<A:Copy> { }
+trait clam<A> { }
struct foo<A> {
x: A,
}
-impl<A:Copy> foo<A> {
+impl<A> foo<A> {
pub fn bar<B,C:clam<A>>(&self, c: C) -> B {
fail!();
}
}
-fn foo<A:Copy>(b: A) -> foo<A> {
+fn foo<A>(b: A) -> foo<A> {
foo {
x: b
}
x: T,
}
-impl<T:Copy> c1<T> {
+impl<T> c1<T> {
pub fn f1(&self, x: int) {
}
}
-fn c1<T:Copy>(x: T) -> c1<T> {
+fn c1<T>(x: T) -> c1<T> {
c1 {
x: x
}
}
-impl<T:Copy> c1<T> {
+impl<T> c1<T> {
pub fn f2(&self, x: int) {
}
}
x: T,
}
-impl<T:Copy> c1<T> {
+impl<T> c1<T> {
pub fn f1(&self, x: T) {}
}
-fn c1<T:Copy>(x: T) -> c1<T> {
+fn c1<T>(x: T) -> c1<T> {
c1 {
x: x
}
}
-impl<T:Copy> c1<T> {
+impl<T> c1<T> {
pub fn f2(&self, x: T) {}
}
}
}
-fn f<T:Copy>(_x: T) {
+fn f<T>(_x: T) {
}
#[deny(non_implicitly_copyable_typarams)]
// than the traits require.
trait A {
- fn b<C:Copy + Freeze,D>(x: C) -> C;
+ fn b<C:Freeze,D>(x: C) -> C;
}
struct 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() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn Matrix4<T:Copy>(m11: T, m12: T, m13: T, m14: T,
- m21: T, m22: T, m23: T, m24: T,
- m31: T, m32: T, m33: T, m34: T,
- m41: T, m42: T, m43: T, m44: T)
- -> Matrix4<T> {
-
+fn Matrix4<T>(m11: T, m12: T, m13: T, m14: T,
+ m21: T, m22: T, m23: T, m24: T,
+ m31: T, m32: T, m33: T, m34: T,
+ m41: T, m42: T, m43: T, m44: T)
+ -> Matrix4<T> {
Matrix4 {
m11: m11, m12: m12, m13: m13, m14: m14,
m21: m21, m22: m22, m23: m23, m24: m24,
// option. This file may not be copied, modified, or distributed
// 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)); }
// option. This file may not be copied, modified, or distributed
// 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]; }
use std::int;
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] {
- fn bind<B:Copy>(&self, f: &fn(&A) -> ~[B]) -> ~[B] {
+ fn bind<B>(&self, f: &fn(&A) -> ~[B]) -> ~[B] {
let mut r = ~[];
for self.iter().advance |elt| {
r.push_all_move(f(elt));
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) {
self.a.serialize(s);
}
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) } }
}
-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));
return head(ls);
}
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;
for iter(h.clone()) |e| {
if *e == n { return Some(i); }
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>(); }
trait vec_utils<T> {
fn length_(&self, ) -> uint;
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] {
fn length_(&self) -> uint { self.len() }
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 = ~[];
for self.iter().advance |elt| {
r.push(f(elt));
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) };
}
a(x);
}
-fn d(x: ~Foo:Send+Copy) {
+fn d(x: ~Foo:Send) {
b(x);
}
}
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] {
- fn map<U:Copy>(&self, f: &fn(&T) -> U) -> ~[U] {
+ fn map<U>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r = ~[];
// FIXME: #7355 generates bad code with Iterator
for std::uint::range(0, self.len()) |i| {
extern mod trait_inheritance_overloading_xc;
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);
}
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);
}
// xfail-fast
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) { }
struct r {
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;
result
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn f<T:Copy>(t: T) -> T {
+fn f<T>(t: T) -> T {
let t1 = t;
t1
}
// Issue #976
-fn f<T:Copy>(x: ~T) {
+fn f<T>(x: ~T) {
let _x2 = x;
}
pub fn main() { }
fn copyable() {
- fn f<T:Copy + Eq>(i: T, j: T) {
+ fn f<T:Eq>(i: T, j: T) {
assert_eq!(i, j);
}
- fn g<T:Copy + Eq>(i: T, j: T) {
+ fn g<T:Eq>(i: T, j: T) {
assert!(i != j);
}
-fn foldl<T, U: Copy+Clone>(
- values: &[T],
- initial: U,
- function: &fn(partial: U, element: &T) -> U
-) -> U {
+fn foldl<T,U:Clone>(values: &[T],
+ initial: U,
+ function: &fn(partial: U, element: &T) -> U)
+ -> U {
match values {
[ref head, ..tail] =>
foldl(tail, function(initial, head), function),
}
}
-fn foldr<T, U: Copy+Clone>(
- values: &[T],
- initial: U,
- function: &fn(element: &T, partial: U) -> U
-) -> U {
+fn foldr<T,U:Clone>(values: &[T],
+ initial: U,
+ function: &fn(element: &T, partial: U) -> U)
+ -> U {
match values {
[..head, ref tail] =>
foldr(head, function(tail, initial), function),