diff options
| author | bors <bors@rust-lang.org> | 2015-05-13 06:43:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-05-13 06:43:05 +0000 |
| commit | fa433875274ff4a7c4cab7d87c1284ba782ef643 (patch) | |
| tree | d8e0dada660d0606983ad1f3efc4761f4b515489 /src/libcore/ops.rs | |
| parent | 30a42faa1c42ce5988241d3af993921246954b1a (diff) | |
| parent | b799cd83cc797b580be2d1492e6ae014848636ee (diff) | |
| download | rust-fa433875274ff4a7c4cab7d87c1284ba782ef643.tar.gz rust-fa433875274ff4a7c4cab7d87c1284ba782ef643.zip | |
Auto merge of #24619 - nrc:rc-coerce, r=nikomatsakis
r? @nikomatsakis (note a few TODOs left in the code where I wasn't sure about stuff).
Diffstat (limited to 'src/libcore/ops.rs')
| -rw-r--r-- | src/libcore/ops.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 55c4264b10c..f16614cfd09 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -70,6 +70,9 @@ use marker::Sized; use fmt; +#[cfg(not(stage0))] +use marker::Unsize; + /// The `Drop` trait is used to run some code when a value goes out of scope. This /// is sometimes called a 'destructor'. /// @@ -1207,3 +1210,43 @@ mod impls { } } } + +/// Trait that indicates that this is a pointer or a wrapper for one, +/// where unsizing can be performed on the pointee. +#[unstable(feature = "core")] +#[cfg(not(stage0))] +#[lang="coerce_unsized"] +pub trait CoerceUnsized<T> { + // Empty. +} + +// &mut T -> &mut U +#[cfg(not(stage0))] +impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {} +// &mut T -> &U +#[cfg(not(stage0))] +impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {} +// &mut T -> *mut U +#[cfg(not(stage0))] +impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {} +// &mut T -> *const U +#[cfg(not(stage0))] +impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {} + +// &T -> &U +#[cfg(not(stage0))] +impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} +// &T -> *const U +#[cfg(not(stage0))] +impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {} + +// *mut T -> *mut U +#[cfg(not(stage0))] +impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} +// *mut T -> *const U +#[cfg(not(stage0))] +impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {} + +// *const T -> *const U +#[cfg(not(stage0))] +impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {} |
