diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-07-10 14:43:25 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-07-17 14:57:53 -0700 |
| commit | e20549ff192edec9d625f1119bcb077c3abaf070 (patch) | |
| tree | 9cf88e584f36dc0d7f9f29a2fae55f0203bbc39c /src/libstd | |
| parent | 99d44d24c7744361b352499b5f54b8f0bab876ec (diff) | |
| download | rust-e20549ff192edec9d625f1119bcb077c3abaf070.tar.gz rust-e20549ff192edec9d625f1119bcb077c3abaf070.zip | |
librustc: Remove all uses of the `Copy` bound.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/clone.rs | 7 | ||||
| -rw-r--r-- | src/libstd/condition.rs | 14 | ||||
| -rw-r--r-- | src/libstd/kinds.rs | 11 | ||||
| -rw-r--r-- | src/libstd/local_data.rs | 2 | ||||
| -rw-r--r-- | src/libstd/num/num.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/strconv.rs | 7 | ||||
| -rw-r--r-- | src/libstd/prelude.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rand.rs | 12 | ||||
| -rw-r--r-- | src/libstd/task/local_data_priv.rs | 6 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 3 | ||||
| -rw-r--r-- | src/libstd/tuple.rs | 10 |
11 files changed, 34 insertions, 43 deletions
diff --git a/src/libstd/clone.rs b/src/libstd/clone.rs index 947aa5708c2..f24bc002a2b 100644 --- a/src/libstd/clone.rs +++ b/src/libstd/clone.rs @@ -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 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. */ diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index 80caa34ce06..10075137017 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -47,7 +47,7 @@ impl<T, U> Condition<T, U> { 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 { @@ -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> { 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 } } @@ -91,7 +92,7 @@ impl<'self, T, U> Condition<'self, T, U> { 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() @@ -100,12 +101,15 @@ impl<'self, T, U> Condition<'self, T, U> { 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 } } diff --git a/src/libstd/kinds.rs b/src/libstd/kinds.rs index 6c16ecc0d4e..f2f8f46e7cd 100644 --- a/src/libstd/kinds.rs +++ b/src/libstd/kinds.rs @@ -18,22 +18,13 @@ intrinsic properties of the type. These classifications, often called 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)]; diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 168bb7c14f0..2c1a3bb29a0 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -59,7 +59,7 @@ use task::local_data_priv::*; #[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 } diff --git a/src/libstd/num/num.rs b/src/libstd/num/num.rs index 4468b51c261..fc199876902 100644 --- a/src/libstd/num/num.rs +++ b/src/libstd/num/num.rs @@ -16,7 +16,6 @@ use cmp::{Eq, ApproxEq, Ord}; 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; @@ -428,7 +427,7 @@ pub trait FromStrRadix { /// - 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(); diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 4661bc20403..ab17c5f175a 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -16,9 +16,8 @@ use core::cmp::{Ord, Eq}; 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}; @@ -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 * 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, @@ -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. */ #[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, diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 8be34896bef..e3e042a4947 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -29,7 +29,7 @@ Rust's prelude has three main parts: // 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}; diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 7d65ba63ff0..76dbc629168 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -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 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 * 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 * @@ -532,7 +532,7 @@ impl<R: Rng> RngUtil for R { } /// 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() } @@ -548,7 +548,7 @@ impl<R: Rng> RngUtil for R { * 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() } @@ -591,7 +591,7 @@ impl<R: Rng> RngUtil for R { } /// 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 diff --git a/src/libstd/task/local_data_priv.rs b/src/libstd/task/local_data_priv.rs index 75fd6eacc1b..d5f4973e8c7 100644 --- a/src/libstd/task/local_data_priv.rs +++ b/src/libstd/task/local_data_priv.rs @@ -15,6 +15,7 @@ use libc; use local_data; use prelude::*; use ptr; +use sys; use task::rt; 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 { 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, diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 396fdaf2e6a..df6f77fd6ce 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -264,7 +264,8 @@ struct TrieNode<T> { 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, diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 841be4df6e2..6201e753bc9 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -13,7 +13,6 @@ #[allow(missing_doc)]; use clone::Clone; -use kinds::Copy; use vec; use vec::ImmutableVector; use iterator::IteratorUtil; @@ -86,8 +85,8 @@ pub trait ExtendedTupleOps<A,B> { } impl<'self, - A:Copy + Clone, - B:Copy + Clone> + A:Clone, + B:Clone> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) { #[inline] @@ -109,10 +108,7 @@ impl<'self, } } -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 { |
