From 843db01bd925279da0a56efde532c9e3ecf73610 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 15 Apr 2015 11:57:29 +1200 Subject: eddyb's changes for DST coercions + lots of rebasing --- src/libcore/intrinsics.rs | 7 +++++++ src/libcore/marker.rs | 8 ++++++++ src/libcore/mem.rs | 34 ++++++++++++++++++++++++++++++++++ src/libcore/nonzero.rs | 5 +++++ src/libcore/ops.rs | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) (limited to 'src/libcore') 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() -> usize; pub fn pref_align_of() -> usize; + #[cfg(not(stage0))] + pub fn size_of_val(_: &T) -> usize; + #[cfg(not(stage0))] + pub fn min_align_of_val(_: &T) -> usize; + #[cfg(not(stage0))] + pub fn drop_in_place(_: *mut T); + /// Gets a static string slice containing the name of a type. pub fn type_name() -> &'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 { + // 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() -> usize { unsafe { intrinsics::size_of::() } } +/// 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(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() -> 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(_val: &T) -> usize { @@ -118,6 +135,22 @@ pub fn min_align_of() -> usize { unsafe { intrinsics::min_align_of::() } } +/// 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(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() -> 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(_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 Deref for NonZero { inner } } + +#[cfg(not(stage0))] // SNAP c64d671 +impl, U: Zeroable> CoerceUnsized> for NonZero {} 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 { + // Empty. +} + +#[cfg(not(stage0))] // SNAP c64d671 +impl<'a, T: ?Sized+Unsize, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {} +#[cfg(not(stage0))] // SNAP c64d671 +impl<'a, 'b: 'a, T: ?Sized+Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {} +#[cfg(not(stage0))] // SNAP c64d671 +impl<'a, T: ?Sized+Unsize, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {} +#[cfg(not(stage0))] // SNAP c64d671 +impl<'a, T: ?Sized+Unsize, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {} + +#[cfg(not(stage0))] // SNAP c64d671 +impl<'a, 'b: 'a, T: ?Sized+Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} +#[cfg(not(stage0))] // SNAP c64d671 +impl<'a, T: ?Sized+Unsize, U: ?Sized> CoerceUnsized<*const U> for &'a T {} + +#[cfg(not(stage0))] // SNAP c64d671 +impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} +#[cfg(not(stage0))] // SNAP c64d671 +impl, U: ?Sized> CoerceUnsized<*const U> for *mut T {} + +#[cfg(not(stage0))] // SNAP c64d671 +impl, U: ?Sized> CoerceUnsized<*const U> for *const T {} -- cgit 1.4.1-3-g733a5