about summary refs log tree commit diff
path: root/src/libcore
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
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')
-rw-r--r--src/libcore/cell.rs1
-rw-r--r--src/libcore/intrinsics.rs7
-rw-r--r--src/libcore/marker.rs8
-rw-r--r--src/libcore/mem.rs34
-rw-r--r--src/libcore/nonzero.rs5
-rw-r--r--src/libcore/ops.rs43
6 files changed, 97 insertions, 1 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index bf5fdb973eb..45a80122104 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -707,5 +707,4 @@ impl<T: ?Sized> UnsafeCell<T> {
         #![allow(trivial_casts)]
         &self.value as *const T as *mut T
     }
-
 }
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index 100b7e70591..d94b8884112 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -193,6 +193,13 @@ extern "rust-intrinsic" {
     pub fn min_align_of<T>() -> usize;
     pub fn pref_align_of<T>() -> usize;
 
+    #[cfg(not(stage0))]
+    pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
+    #[cfg(not(stage0))]
+    pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
+    #[cfg(not(stage0))]
+    pub fn drop_in_place<T: ?Sized>(_: *mut T);
+
     /// Gets a static string slice containing the name of a type.
     pub fn type_name<T: ?Sized>() -> &'static str;
 
diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs
index 3aaedaeb813..5909c5cc30e 100644
--- a/src/libcore/marker.rs
+++ b/src/libcore/marker.rs
@@ -53,6 +53,14 @@ pub trait Sized {
     // Empty.
 }
 
+/// Types that can be "unsized" to a dynamically sized type.
+#[unstable(feature = "core")]
+#[cfg(not(stage0))]
+#[lang="unsize"]
+pub trait Unsize<T> {
+    // Empty.
+}
+
 /// Types that can be copied by simply copying bits (i.e. `memcpy`).
 ///
 /// By default, variable bindings have 'move semantics.' In other
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs
index a149af3a440..173b73fdb09 100644
--- a/src/libcore/mem.rs
+++ b/src/libcore/mem.rs
@@ -86,6 +86,22 @@ pub fn size_of<T>() -> usize {
     unsafe { intrinsics::size_of::<T>() }
 }
 
+/// Returns the size of the type that `val` points to in bytes.
+///
+/// # Examples
+///
+/// ```
+/// use std::mem;
+///
+/// assert_eq!(4, mem::size_of_val(&5i32));
+/// ```
+#[cfg(not(stage0))]
+#[inline]
+#[stable(feature = "rust1", since = "1.0.0")]
+pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
+    unsafe { intrinsics::size_of_val(val) }
+}
+
 /// Returns the size of the type that `_val` points to in bytes.
 ///
 /// # Examples
@@ -95,6 +111,7 @@ pub fn size_of<T>() -> usize {
 ///
 /// assert_eq!(4, mem::size_of_val(&5i32));
 /// ```
+#[cfg(stage0)]
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub fn size_of_val<T>(_val: &T) -> usize {
@@ -118,6 +135,22 @@ pub fn min_align_of<T>() -> usize {
     unsafe { intrinsics::min_align_of::<T>() }
 }
 
+/// Returns the ABI-required minimum alignment of the type of the value that `val` points to
+///
+/// # Examples
+///
+/// ```
+/// use std::mem;
+///
+/// assert_eq!(4, mem::min_align_of_val(&5i32));
+/// ```
+#[cfg(not(stage0))]
+#[inline]
+#[stable(feature = "rust1", since = "1.0.0")]
+pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
+    unsafe { intrinsics::min_align_of_val(val) }
+}
+
 /// Returns the ABI-required minimum alignment of the type of the value that `_val` points to
 ///
 /// # Examples
@@ -127,6 +160,7 @@ pub fn min_align_of<T>() -> usize {
 ///
 /// assert_eq!(4, mem::min_align_of_val(&5i32));
 /// ```
+#[cfg(stage0)]
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub fn min_align_of_val<T>(_val: &T) -> usize {
diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs
index 13b6468105d..59819fd500d 100644
--- a/src/libcore/nonzero.rs
+++ b/src/libcore/nonzero.rs
@@ -12,6 +12,8 @@
 
 use marker::Sized;
 use ops::Deref;
+#[cfg(not(stage0))]
+use ops::CoerceUnsized;
 
 /// Unsafe trait to indicate what types are usable with the NonZero struct
 pub unsafe trait Zeroable {}
@@ -54,3 +56,6 @@ impl<T: Zeroable> Deref for NonZero<T> {
         inner
     }
 }
+
+#[cfg(not(stage0))]
+impl<T: Zeroable+CoerceUnsized<U>, U: Zeroable> CoerceUnsized<NonZero<U>> for NonZero<T> {}
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 {}