diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-21 00:04:09 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-12-21 09:27:34 -0800 |
| commit | de7abcf6d3d2d0928fa03a7522e23f4aba0d5254 (patch) | |
| tree | 88b1f4c9b7d4f7c3e0bc27ae7dce4cb355fad75a /src | |
| parent | fc40812b0f7a07834b2ad557ec3d5a0e98e80f85 (diff) | |
| parent | 14a5992ef614a76cd36972191ea4507a3d3daccb (diff) | |
| download | rust-de7abcf6d3d2d0928fa03a7522e23f4aba0d5254.tar.gz rust-de7abcf6d3d2d0928fa03a7522e23f4aba0d5254.zip | |
rollup merge of #20014: kballard/unsized-marker-type-params
Tweak CovariantType, ContravariantType, and InvariantType to allow their type parameter to be unsized.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/kinds.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/libcore/kinds.rs b/src/libcore/kinds.rs index 5e2c30f145f..b0f46e3d68c 100644 --- a/src/libcore/kinds.rs +++ b/src/libcore/kinds.rs @@ -91,7 +91,8 @@ pub trait Sync for Sized? { /// implemented using unsafe code. In that case, you may want to embed /// some of the marker types below into your type. pub mod marker { - use super::Copy; + use super::{Copy,Sized}; + use clone::Clone; /// A marker type whose type parameter `T` is considered to be /// covariant with respect to the type itself. This is (typically) @@ -131,10 +132,13 @@ pub mod marker { /// (for example, `S<&'static int>` is a subtype of `S<&'a int>` /// for some lifetime `'a`, but not the other way around). #[lang="covariant_type"] - #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] - pub struct CovariantType<T>; + #[deriving(PartialEq, Eq, PartialOrd, Ord)] + pub struct CovariantType<Sized? T>; - impl<T> Copy for CovariantType<T> {} + impl<Sized? T> Copy for CovariantType<T> {} + impl<Sized? T> Clone for CovariantType<T> { + fn clone(&self) -> CovariantType<T> { *self } + } /// A marker type whose type parameter `T` is considered to be /// contravariant with respect to the type itself. This is (typically) @@ -176,10 +180,13 @@ pub mod marker { /// function requires arguments of type `T`, it must also accept /// arguments of type `U`, hence such a conversion is safe. #[lang="contravariant_type"] - #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] - pub struct ContravariantType<T>; + #[deriving(PartialEq, Eq, PartialOrd, Ord)] + pub struct ContravariantType<Sized? T>; - impl<T> Copy for ContravariantType<T> {} + impl<Sized? T> Copy for ContravariantType<T> {} + impl<Sized? T> Clone for ContravariantType<T> { + fn clone(&self) -> ContravariantType<T> { *self } + } /// A marker type whose type parameter `T` is considered to be /// invariant with respect to the type itself. This is (typically) @@ -203,10 +210,13 @@ pub mod marker { /// never written, but in fact `Cell` uses unsafe code to achieve /// interior mutability. #[lang="invariant_type"] - #[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)] - pub struct InvariantType<T>; + #[deriving(PartialEq, Eq, PartialOrd, Ord)] + pub struct InvariantType<Sized? T>; - impl<T> Copy for InvariantType<T> {} + impl<Sized? T> Copy for InvariantType<T> {} + impl<Sized? T> Clone for InvariantType<T> { + fn clone(&self) -> InvariantType<T> { *self } + } /// As `CovariantType`, but for lifetime parameters. Using /// `CovariantLifetime<'a>` indicates that it is ok to substitute |
