diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-04-15 11:57:29 +1200 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-05-13 14:19:51 +1200 |
| commit | 843db01bd925279da0a56efde532c9e3ecf73610 (patch) | |
| tree | eed89761dcb0ddeb578ca24357ef680787eabb43 /src/libcore | |
| parent | c2b30b86df6b34ba19e87e63402e43d9e81a64fb (diff) | |
| download | rust-843db01bd925279da0a56efde532c9e3ecf73610.tar.gz rust-843db01bd925279da0a56efde532c9e3ecf73610.zip | |
eddyb's changes for DST coercions
+ lots of rebasing
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/intrinsics.rs | 7 | ||||
| -rw-r--r-- | src/libcore/marker.rs | 8 | ||||
| -rw-r--r-- | src/libcore/mem.rs | 34 | ||||
| -rw-r--r-- | src/libcore/nonzero.rs | 5 | ||||
| -rw-r--r-- | src/libcore/ops.rs | 34 |
5 files changed, 88 insertions, 0 deletions
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..968f68a78a7 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))] // 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 diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index a149af3a440..bb94cd886d7 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))] // 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 { diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index 13b6468105d..85957382826 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -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> {} diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 55c4264b10c..1a2473fda41 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -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 {} |
