From 23bae856b7f3a037caffbf6af6f376a7d48058cd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 15 Dec 2014 19:40:25 -0800 Subject: [PATCH] std: Second-pass stabilization of `mem` This commit takes a second pass through the `std::mem` module for stabilization. The only remaining non-stable items in this module were `forget`, `transmute`, `copy_lifetime`, and `copy_lifetime_mut`. The `forget` and `transmute` intrinsics themselves were marked `#[stable]` to propgate into the `core::mem` module so they would be marked stable. The `copy_lifetime` functions were left `unstable`, but `Sized?` annotations were added to the parameters to allow more general use with DSTs. The `size_of_val`, `min_align_of_val`, and `align_of_val` functions would like to grow `Sized?` bounds, but this is a backwards compatible change that currently ICEs the compiler, so this change was not made at this time. Finally, the module itself was declared `#![stable]` in this pass. --- src/libcore/intrinsics.rs | 2 ++ src/libcore/mem.rs | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 2fc4d23e7fd7..e2afee9905d7 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -217,6 +217,7 @@ extern "rust-intrinsic" { /// /// `forget` is unsafe because the caller is responsible for /// ensuring the argument is deallocated already. + #[stable] pub fn forget(_: T) -> (); /// Unsafely transforms a value of one type into a value of another type. @@ -232,6 +233,7 @@ extern "rust-intrinsic" { /// let v: &[u8] = unsafe { mem::transmute("L") }; /// assert!(v == [76u8]); /// ``` + #[stable] pub fn transmute(e: T) -> U; /// Gives the address for the return value of the enclosing function. diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 937f73a32627..6747d12e0284 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -13,9 +13,13 @@ //! This module contains functions for querying the size and alignment of //! types, initializing and manipulating memory. +#![stable] + +use kinds::Sized; use intrinsics; use ptr; +#[stable] pub use intrinsics::transmute; /// Moves a thing into the void. @@ -223,7 +227,8 @@ pub unsafe fn transmute_copy(src: &T) -> U { #[inline] #[unstable = "this function may be removed in the future due to its \ questionable utility"] -pub unsafe fn copy_lifetime<'a, S, T:'a>(_ptr: &'a S, ptr: &T) -> &'a T { +pub unsafe fn copy_lifetime<'a, Sized? S, Sized? T: 'a>(_ptr: &'a S, + ptr: &T) -> &'a T { transmute(ptr) } @@ -231,7 +236,8 @@ pub unsafe fn copy_lifetime<'a, S, T:'a>(_ptr: &'a S, ptr: &T) -> &'a T { #[inline] #[unstable = "this function may be removed in the future due to its \ questionable utility"] -pub unsafe fn copy_mut_lifetime<'a, S, T:'a>(_ptr: &'a mut S, - ptr: &mut T) -> &'a mut T { +pub unsafe fn copy_mut_lifetime<'a, Sized? S, Sized? T: 'a>(_ptr: &'a mut S, + ptr: &mut T) + -> &'a mut T { transmute(ptr) }