diff options
| author | bors <bors@rust-lang.org> | 2015-02-23 20:47:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-23 20:47:30 +0000 |
| commit | 91a5a1ab4ad054c8dccf49f6f409542f82683cfc (patch) | |
| tree | 1c2a90b8e1aac6793a0fbf6350778a5b9ac65dae /src/liballoc | |
| parent | f0f7ca27de6b4e03f30012656dad270cda55a363 (diff) | |
| parent | ee6f2a1ad6ab79ed954cd96fff6eaddcdfb6a043 (diff) | |
| download | rust-91a5a1ab4ad054c8dccf49f6f409542f82683cfc.tar.gz rust-91a5a1ab4ad054c8dccf49f6f409542f82683cfc.zip | |
Auto merge of #22724 - Manishearth:rollup, r=alexcrichton
Seems to pass `check-stage1`, but I had to tweak some things so it's going through the test gauntlet again.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 13 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 9 |
2 files changed, 14 insertions, 8 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index ce889c79601..a93872dfe36 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -105,15 +105,16 @@ impl<T : ?Sized> Box<T> { /// After this function call, pointer is owned by resulting box. /// In particular, it means that `Box` destructor calls destructor /// of `T` and releases memory. Since the way `Box` allocates and - /// releases memory is unspecified, so the only valid pointer to - /// pass to this function is the one taken from another `Box` with - /// `box::into_raw` function. + /// releases memory is unspecified, the only valid pointer to pass + /// to this function is the one taken from another `Box` with + /// `boxed::into_raw` function. /// /// Function is unsafe, because improper use of this function may /// lead to memory problems like double-free, for example if the /// function is called twice on the same raw pointer. #[unstable(feature = "alloc", reason = "may be renamed or moved out of Box scope")] + #[inline] pub unsafe fn from_raw(raw: *mut T) -> Self { mem::transmute(raw) } @@ -141,6 +142,7 @@ impl<T : ?Sized> Box<T> { /// ``` #[unstable(feature = "alloc", reason = "may be renamed")] +#[inline] pub unsafe fn into_raw<T : ?Sized>(b: Box<T>) -> *mut T { mem::transmute(b) } @@ -248,11 +250,12 @@ impl BoxAny for Box<Any> { if self.is::<T>() { unsafe { // Get the raw representation of the trait object + let raw = into_raw(self); let to: TraitObject = - mem::transmute::<Box<Any>, TraitObject>(self); + mem::transmute::<*mut Any, TraitObject>(raw); // Extract the data pointer - Ok(mem::transmute(to.data)) + Ok(Box::from_raw(to.data as *mut T)) } } else { Err(self) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index ed7d34de7a6..f57286bbf11 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -143,7 +143,10 @@ //! ``` #![stable(feature = "rust1", since = "1.0.0")] - +#[cfg(not(test))] +use boxed; +#[cfg(test)] +use std::boxed; use core::cell::Cell; use core::clone::Clone; use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering}; @@ -151,7 +154,7 @@ use core::default::Default; use core::fmt; use core::hash::{Hasher, Hash}; use core::marker; -use core::mem::{transmute, min_align_of, size_of, forget}; +use core::mem::{min_align_of, size_of, forget}; use core::nonzero::NonZero; use core::ops::{Deref, Drop}; use core::option::Option; @@ -201,7 +204,7 @@ impl<T> Rc<T> { // there is an implicit weak pointer owned by all the strong pointers, which // ensures that the weak destructor never frees the allocation while the strong // destructor is running, even if the weak pointer is stored inside the strong one. - _ptr: NonZero::new(transmute(box RcBox { + _ptr: NonZero::new(boxed::into_raw(box RcBox { value: value, strong: Cell::new(1), weak: Cell::new(1) |
