Skip to content

Commit de7abcf

Browse files
committed
rollup merge of rust-lang#20014: kballard/unsized-marker-type-params
Tweak CovariantType, ContravariantType, and InvariantType to allow their type parameter to be unsized.
2 parents fc40812 + 14a5992 commit de7abcf

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/libcore/kinds.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ pub trait Sync for Sized? {
9191
/// implemented using unsafe code. In that case, you may want to embed
9292
/// some of the marker types below into your type.
9393
pub mod marker {
94-
use super::Copy;
94+
use super::{Copy,Sized};
95+
use clone::Clone;
9596

9697
/// A marker type whose type parameter `T` is considered to be
9798
/// covariant with respect to the type itself. This is (typically)
@@ -131,10 +132,13 @@ pub mod marker {
131132
/// (for example, `S<&'static int>` is a subtype of `S<&'a int>`
132133
/// for some lifetime `'a`, but not the other way around).
133134
#[lang="covariant_type"]
134-
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)]
135-
pub struct CovariantType<T>;
135+
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
136+
pub struct CovariantType<Sized? T>;
136137

137-
impl<T> Copy for CovariantType<T> {}
138+
impl<Sized? T> Copy for CovariantType<T> {}
139+
impl<Sized? T> Clone for CovariantType<T> {
140+
fn clone(&self) -> CovariantType<T> { *self }
141+
}
138142

139143
/// A marker type whose type parameter `T` is considered to be
140144
/// contravariant with respect to the type itself. This is (typically)
@@ -176,10 +180,13 @@ pub mod marker {
176180
/// function requires arguments of type `T`, it must also accept
177181
/// arguments of type `U`, hence such a conversion is safe.
178182
#[lang="contravariant_type"]
179-
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)]
180-
pub struct ContravariantType<T>;
183+
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
184+
pub struct ContravariantType<Sized? T>;
181185

182-
impl<T> Copy for ContravariantType<T> {}
186+
impl<Sized? T> Copy for ContravariantType<T> {}
187+
impl<Sized? T> Clone for ContravariantType<T> {
188+
fn clone(&self) -> ContravariantType<T> { *self }
189+
}
183190

184191
/// A marker type whose type parameter `T` is considered to be
185192
/// invariant with respect to the type itself. This is (typically)
@@ -203,10 +210,13 @@ pub mod marker {
203210
/// never written, but in fact `Cell` uses unsafe code to achieve
204211
/// interior mutability.
205212
#[lang="invariant_type"]
206-
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)]
207-
pub struct InvariantType<T>;
213+
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
214+
pub struct InvariantType<Sized? T>;
208215

209-
impl<T> Copy for InvariantType<T> {}
216+
impl<Sized? T> Copy for InvariantType<T> {}
217+
impl<Sized? T> Clone for InvariantType<T> {
218+
fn clone(&self) -> InvariantType<T> { *self }
219+
}
210220

211221
/// As `CovariantType`, but for lifetime parameters. Using
212222
/// `CovariantLifetime<'a>` indicates that it is ok to substitute

0 commit comments

Comments
 (0)