eddyb's changes for DST coercions

+ lots of rebasing
This commit is contained in:
Nick Cameron 2015-04-15 11:57:29 +12:00
parent c2b30b86df
commit 843db01bd9
40 changed files with 1019 additions and 514 deletions

View file

@ -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;

View file

@ -53,6 +53,14 @@ pub trait Sized {
// Empty.
}
/// Types that can be "unsized" to a dynamically sized type.
#[unstable(feature = "core")]
#[cfg(not(stage0))] // SNAP c64d671
#[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

View file

@ -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))] // SNAP c64d671
#[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)] // SNAP c64d671
#[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))] // SNAP c64d671
#[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)] // SNAP c64d671
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn min_align_of_val<T>(_val: &T) -> usize {

View file

@ -12,6 +12,8 @@
use marker::Sized;
use ops::Deref;
#[cfg(not(stage0))] // SNAP c64d671
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))] // SNAP c64d671
impl<T: Zeroable+CoerceUnsized<U>, U: Zeroable> CoerceUnsized<NonZero<U>> for NonZero<T> {}

View file

@ -70,6 +70,9 @@
use marker::Sized;
use fmt;
#[cfg(not(stage0))] // SNAP c64d671
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,34 @@ 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))] // SNAP c64d671
#[lang="coerce_unsized"]
pub trait CoerceUnsized<T> {
// Empty.
}
#[cfg(not(stage0))] // SNAP c64d671
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
#[cfg(not(stage0))] // SNAP c64d671
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}