about summary refs log tree commit diff
path: root/src/libcore/ops.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-13 06:43:05 +0000
committerbors <bors@rust-lang.org>2015-05-13 06:43:05 +0000
commitfa433875274ff4a7c4cab7d87c1284ba782ef643 (patch)
treed8e0dada660d0606983ad1f3efc4761f4b515489 /src/libcore/ops.rs
parent30a42faa1c42ce5988241d3af993921246954b1a (diff)
parentb799cd83cc797b580be2d1492e6ae014848636ee (diff)
downloadrust-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.rs43
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 {}