From: Kevin Ballard Date: Fri, 19 Dec 2014 02:31:29 +0000 (-0800) Subject: Allow marker types to have unsized parameters X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=14a5992ef614a76cd36972191ea4507a3d3daccb;p=rust.git Allow marker types to have unsized parameters Tweak CovariantType, ContravariantType, and InvariantType to allow their type parameter to be unsized. --- diff --git a/src/libcore/kinds.rs b/src/libcore/kinds.rs index 69f65e23389..bf1a7ec2999 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; + #[deriving(PartialEq, Eq, PartialOrd, Ord)] + pub struct CovariantType; - impl Copy for CovariantType {} + impl Copy for CovariantType {} + impl Clone for CovariantType { + fn clone(&self) -> CovariantType { *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 @@ impl Copy for CovariantType {} /// 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; + #[deriving(PartialEq, Eq, PartialOrd, Ord)] + pub struct ContravariantType; - impl Copy for ContravariantType {} + impl Copy for ContravariantType {} + impl Clone for ContravariantType { + fn clone(&self) -> ContravariantType { *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 @@ impl Copy for ContravariantType {} /// 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; + #[deriving(PartialEq, Eq, PartialOrd, Ord)] + pub struct InvariantType; - impl Copy for InvariantType {} + impl Copy for InvariantType {} + impl Clone for InvariantType { + fn clone(&self) -> InvariantType { *self } + } /// As `CovariantType`, but for lifetime parameters. Using /// `CovariantLifetime<'a>` indicates that it is ok to substitute