From e0ede9c6b3894851b800a323757857eba07943b5 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 10 Jul 2014 14:19:17 -0700 Subject: [PATCH] Stabilization for `owned` (now `boxed`) and `cell` This PR is the outcome of the library stabilization meeting for the `liballoc::owned` and `libcore::cell` modules. Aside from the stability attributes, there are a few breaking changes: * The `owned` modules is now named `boxed`, to better represent its contents. (`box` was unavailable, since it's a keyword.) This will help avoid the misconception that `Box` plays a special role wrt ownership. * The `AnyOwnExt` extension trait is renamed to `BoxAny`, and its `move` method is renamed to `downcast`, in both cases to improve clarity. * The recently-added `AnySendOwnExt` extension trait is removed; it was not being used and is unnecessary. [breaking-change] --- src/liballoc/{owned.rs => boxed.rs} | 59 ++++++------------- src/liballoc/lib.rs | 14 +++-- src/libcollections/btree.rs | 2 +- src/libcollections/dlist.rs | 2 +- src/libcollections/hash/mod.rs | 2 +- src/libcollections/treemap.rs | 2 +- src/libcollections/trie.rs | 2 +- src/libcore/cell.rs | 24 +++++++- src/librustrt/args.rs | 2 +- src/librustrt/at_exit_imp.rs | 2 +- src/librustrt/lib.rs | 2 +- src/librustrt/local.rs | 2 +- src/librustrt/local_data.rs | 2 +- src/librustrt/local_ptr.rs | 6 +- src/librustrt/rtio.rs | 2 +- src/librustrt/stack.rs | 2 +- src/librustrt/task.rs | 4 +- src/librustrt/thread.rs | 6 +- src/librustrt/unwind.rs | 2 +- src/libstd/collections/lru_cache.rs | 2 +- src/libstd/failure.rs | 2 +- src/libstd/io/fs.rs | 2 +- src/libstd/io/mod.rs | 2 +- src/libstd/io/net/tcp.rs | 2 +- src/libstd/io/net/udp.rs | 2 +- src/libstd/io/net/unix.rs | 2 +- src/libstd/io/pipe.rs | 2 +- src/libstd/io/process.rs | 2 +- src/libstd/io/signal.rs | 2 +- src/libstd/io/stdio.rs | 2 +- src/libstd/io/timer.rs | 2 +- src/libstd/io/util.rs | 4 +- src/libstd/lib.rs | 7 ++- src/libstd/prelude.rs | 2 +- src/libstd/task.rs | 12 ++-- src/libsync/atomics.rs | 2 +- src/libsync/comm/mod.rs | 2 +- src/libsync/comm/oneshot.rs | 2 +- src/libsync/comm/select.rs | 2 +- src/libsync/comm/shared.rs | 2 +- src/libsync/comm/stream.rs | 2 +- src/libsync/comm/sync.rs | 2 +- src/libsync/deque.rs | 2 +- src/libsync/mpsc_queue.rs | 2 +- src/libsync/mutex.rs | 2 +- src/libsync/spsc_queue.rs | 2 +- src/test/compile-fail/new-box-syntax-bad.rs | 2 +- src/test/run-pass/new-box-syntax.rs | 3 +- .../run-pass/unit-like-struct-drop-run.rs | 4 +- 49 files changed, 112 insertions(+), 107 deletions(-) rename src/liballoc/{owned.rs => boxed.rs} (77%) diff --git a/src/liballoc/owned.rs b/src/liballoc/boxed.rs similarity index 77% rename from src/liballoc/owned.rs rename to src/liballoc/boxed.rs index addec396bbe..56506d798d9 100644 --- a/src/liballoc/owned.rs +++ b/src/liballoc/boxed.rs @@ -16,7 +16,6 @@ use core::default::Default; use core::fmt; use core::intrinsics; -use core::kinds::Send; use core::mem; use core::option::Option; use core::raw::TraitObject; @@ -27,17 +26,19 @@ /// /// The following two examples are equivalent: /// -/// use std::owned::HEAP; +/// use std::boxed::HEAP; /// /// # struct Bar; /// # impl Bar { fn new(_a: int) { } } /// let foo = box(HEAP) Bar::new(2); /// let foo = box Bar::new(2); -#[lang="exchange_heap"] +#[lang = "exchange_heap"] +#[experimental = "may be renamed; uncertain about custom allocator design"] pub static HEAP: () = (); /// A type that represents a uniquely-owned value. -#[lang="owned_box"] +#[lang = "owned_box"] +#[unstable = "custom allocators will add an additional type parameter (with default)"] pub struct Box(*mut T); impl Default for Box { @@ -57,7 +58,6 @@ fn clone_from(&mut self, source: &Box) { } } -// box pointers impl PartialEq for Box { #[inline] fn eq(&self, other: &Box) -> bool { *(*self) == *(*other) } @@ -85,48 +85,27 @@ fn cmp(&self, other: &Box) -> Ordering { (**self).cmp(*other) } impl Eq for Box {} /// Extension methods for an owning `Any` trait object -pub trait AnyOwnExt { +#[unstable = "post-DST, the signature of `downcast` will change to take `Box`"] +pub trait BoxAny { /// Returns the boxed value if it is of type `T`, or /// `Err(Self)` if it isn't. - fn move(self) -> Result, Self>; -} - -impl AnyOwnExt for Box { - #[inline] - fn move(self) -> Result, Box> { - if self.is::() { - unsafe { - // Get the raw representation of the trait object - let to: TraitObject = - *mem::transmute::<&Box, &TraitObject>(&self); - - // Prevent destructor on self being run - intrinsics::forget(self); + fn downcast(self) -> Result, Self>; - // Extract the data pointer - Ok(mem::transmute(to.data)) - } - } else { - Err(self) - } + /// Deprecated; this method has been renamed to `downcast`. + #[deprecated = "use downcast instead"] + fn move(self) -> Result, Self> { + self.downcast::() } } -/// Extension methods for an owning `Any+Send` trait object -pub trait AnySendOwnExt { - /// Returns the boxed value if it is of type `T`, or - /// `Err(Self)` if it isn't. - fn move_send(self) -> Result, Self>; -} - -impl AnySendOwnExt for Box { +impl BoxAny for Box { #[inline] - fn move_send(self) -> Result, Box> { + fn downcast(self) -> Result, Box> { if self.is::() { unsafe { // Get the raw representation of the trait object let to: TraitObject = - *mem::transmute::<&Box, &TraitObject>(&self); + *mem::transmute::<&Box, &TraitObject>(&self); // Prevent destructor on self being run intrinsics::forget(self); @@ -166,11 +145,11 @@ fn any_move() { let a = box 8u as Box; let b = box Test as Box; - match a.move::() { + match a.downcast::() { Ok(a) => { assert!(a == box 8u); } Err(..) => fail!() } - match b.move::() { + match b.downcast::() { Ok(a) => { assert!(a == box Test); } Err(..) => fail!() } @@ -178,8 +157,8 @@ fn any_move() { let a = box 8u as Box; let b = box Test as Box; - assert!(a.move::>().is_err()); - assert!(b.move::>().is_err()); + assert!(a.downcast::>().is_err()); + assert!(b.downcast::>().is_err()); } #[test] diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 80b6cee2a9d..6ae91f38971 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -21,11 +21,11 @@ //! //! Currently, there are four major definitions in this library. //! -//! ## Owned pointers +//! ## Boxed values //! -//! The [`Box`](owned/index.html) type is the core owned pointer type in rust. +//! The [`Box`](boxed/index.html) type is the core owned pointer type in rust. //! There can only be one owner of a `Box`, and the owner can decide to mutate -//! the contents. +//! the contents, which live on the heap. //! //! This type can be sent among tasks efficiently as the size of a `Box` value //! is just a pointer. Tree-like data structures are often built on owned @@ -82,6 +82,12 @@ #[cfg(test)] #[phase(plugin, link)] extern crate std; #[cfg(test)] #[phase(plugin, link)] extern crate log; +// The deprecated name of the boxed module + +#[deprecated = "use boxed instead"] +#[cfg(not(test))] +pub use owned = boxed; + // Heaps provided for low-level allocation strategies pub mod heap; @@ -91,7 +97,7 @@ // Primitive types using the heaps above #[cfg(not(test))] -pub mod owned; +pub mod boxed; pub mod arc; pub mod rc; diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index 2d138b1a189..6ee68f74438 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -20,7 +20,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::fmt; use core::fmt::Show; diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index ed2d6738876..226dd5a2356 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -23,7 +23,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::default::Default; use core::fmt; use core::iter; diff --git a/src/libcollections/hash/mod.rs b/src/libcollections/hash/mod.rs index e3d1c9a3216..35738320715 100644 --- a/src/libcollections/hash/mod.rs +++ b/src/libcollections/hash/mod.rs @@ -65,7 +65,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use alloc::rc::Rc; use core::intrinsics::TypeId; use core::mem; diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 1451bf9d7c7..bb596530d4a 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -14,7 +14,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::default::Default; use core::fmt; use core::fmt::Show; diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 9b6355e121b..29ec85590b3 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -12,7 +12,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::default::Default; use core::mem::zeroed; use core::mem; diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 355ee7c7a16..51b5d0aded8 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -163,11 +163,13 @@ use ty::Unsafe; /// A mutable memory location that admits only `Copy` data. +#[unstable = "likely to be renamed; otherwise stable"] pub struct Cell { value: Unsafe, noshare: marker::NoShare, } +#[stable] impl Cell { /// Creates a new `Cell` containing the given value. pub fn new(value: T) -> Cell { @@ -192,13 +194,14 @@ pub fn set(&self, value: T) { } } -#[unstable] +#[unstable = "waiting for `Clone` trait to become stable"] impl Clone for Cell { fn clone(&self) -> Cell { Cell::new(self.get()) } } +#[unstable = "waiting for `PartialEq` trait to become stable"] impl PartialEq for Cell { fn eq(&self, other: &Cell) -> bool { self.get() == other.get() @@ -206,6 +209,7 @@ fn eq(&self, other: &Cell) -> bool { } /// A mutable memory location with dynamically checked borrow rules +#[unstable = "likely to be renamed; otherwise stable"] pub struct RefCell { value: Unsafe, borrow: Cell, @@ -221,6 +225,7 @@ pub struct RefCell { impl RefCell { /// Create a new `RefCell` containing `value` + #[stable] pub fn new(value: T) -> RefCell { RefCell { value: Unsafe::new(value), @@ -231,6 +236,7 @@ pub fn new(value: T) -> RefCell { } /// Consumes the `RefCell`, returning the wrapped value. + #[unstable = "may be renamed, depending on global conventions"] pub fn unwrap(self) -> T { debug_assert!(self.borrow.get() == UNUSED); unsafe{self.value.unwrap()} @@ -242,6 +248,7 @@ pub fn unwrap(self) -> T { /// immutable borrows can be taken out at the same time. /// /// Returns `None` if the value is currently mutably borrowed. + #[unstable = "may be renamed, depending on global conventions"] pub fn try_borrow<'a>(&'a self) -> Option> { match self.borrow.get() { WRITING => None, @@ -260,6 +267,7 @@ pub fn try_borrow<'a>(&'a self) -> Option> { /// # Failure /// /// Fails if the value is currently mutably borrowed. + #[unstable] pub fn borrow<'a>(&'a self) -> Ref<'a, T> { match self.try_borrow() { Some(ptr) => ptr, @@ -273,6 +281,7 @@ pub fn borrow<'a>(&'a self) -> Ref<'a, T> { /// cannot be borrowed while this borrow is active. /// /// Returns `None` if the value is currently borrowed. + #[unstable = "may be renamed, depending on global conventions"] pub fn try_borrow_mut<'a>(&'a self) -> Option> { match self.borrow.get() { UNUSED => { @@ -291,6 +300,7 @@ pub fn try_borrow_mut<'a>(&'a self) -> Option> { /// # Failure /// /// Fails if the value is currently borrowed. + #[unstable] pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> { match self.try_borrow_mut() { Some(ptr) => ptr, @@ -299,13 +309,14 @@ pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> { } } -#[unstable] +#[unstable = "waiting for `Clone` to become stable"] impl Clone for RefCell { fn clone(&self) -> RefCell { RefCell::new(self.borrow().clone()) } } +#[unstable = "waiting for `PartialEq` to become stable"] impl PartialEq for RefCell { fn eq(&self, other: &RefCell) -> bool { *self.borrow() == *other.borrow() @@ -313,6 +324,7 @@ fn eq(&self, other: &RefCell) -> bool { } /// Wraps a borrowed reference to a value in a `RefCell` box. +#[unstable] pub struct Ref<'b, T> { // FIXME #12808: strange name to try to avoid interfering with // field accesses of the contained type via Deref @@ -320,6 +332,7 @@ pub struct Ref<'b, T> { } #[unsafe_destructor] +#[unstable] impl<'b, T> Drop for Ref<'b, T> { fn drop(&mut self) { let borrow = self._parent.borrow.get(); @@ -328,6 +341,7 @@ fn drop(&mut self) { } } +#[unstable = "waiting for `Deref` to become stable"] impl<'b, T> Deref for Ref<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { @@ -341,7 +355,7 @@ fn deref<'a>(&'a self) -> &'a T { /// /// A `Clone` implementation would interfere with the widespread /// use of `r.borrow().clone()` to clone the contents of a `RefCell`. -#[experimental] +#[experimental = "likely to be moved to a method, pending language changes"] pub fn clone_ref<'b, T>(orig: &Ref<'b, T>) -> Ref<'b, T> { // Since this Ref exists, we know the borrow flag // is not set to WRITING. @@ -355,6 +369,7 @@ pub fn clone_ref<'b, T>(orig: &Ref<'b, T>) -> Ref<'b, T> { } /// Wraps a mutable borrowed reference to a value in a `RefCell` box. +#[unstable] pub struct RefMut<'b, T> { // FIXME #12808: strange name to try to avoid interfering with // field accesses of the contained type via Deref @@ -362,6 +377,7 @@ pub struct RefMut<'b, T> { } #[unsafe_destructor] +#[unstable] impl<'b, T> Drop for RefMut<'b, T> { fn drop(&mut self) { let borrow = self._parent.borrow.get(); @@ -370,6 +386,7 @@ fn drop(&mut self) { } } +#[unstable = "waiting for `Deref` to become stable"] impl<'b, T> Deref for RefMut<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { @@ -377,6 +394,7 @@ fn deref<'a>(&'a self) -> &'a T { } } +#[unstable = "waiting for `DerefMut` to become stable"] impl<'b, T> DerefMut for RefMut<'b, T> { #[inline] fn deref_mut<'a>(&'a mut self) -> &'a mut T { diff --git a/src/librustrt/args.rs b/src/librustrt/args.rs index 3c0a4aae251..af6de0cf605 100644 --- a/src/librustrt/args.rs +++ b/src/librustrt/args.rs @@ -45,7 +45,7 @@ pub fn clone() -> Option>> { imp::clone() } mod imp { use core::prelude::*; - use alloc::owned::Box; + use alloc::boxed::Box; use collections::vec::Vec; use core::mem; use core::slice; diff --git a/src/librustrt/at_exit_imp.rs b/src/librustrt/at_exit_imp.rs index dcba7fb7cb6..1faf492e498 100644 --- a/src/librustrt/at_exit_imp.rs +++ b/src/librustrt/at_exit_imp.rs @@ -14,7 +14,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use collections::vec::Vec; use core::atomics; use core::mem; diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index c830b2e122e..0b611381aa2 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -37,7 +37,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::any::Any; use task::{Task, BlockedTask, TaskOpts}; diff --git a/src/librustrt/local.rs b/src/librustrt/local.rs index 7fe9dbc6d4f..bdb1c60b6d6 100644 --- a/src/librustrt/local.rs +++ b/src/librustrt/local.rs @@ -10,7 +10,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use local_ptr; use task::Task; diff --git a/src/librustrt/local_data.rs b/src/librustrt/local_data.rs index d4c87e9fc05..ace53478d0a 100644 --- a/src/librustrt/local_data.rs +++ b/src/librustrt/local_data.rs @@ -40,7 +40,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use collections::vec::Vec; use core::kinds::marker; use core::mem; diff --git a/src/librustrt/local_ptr.rs b/src/librustrt/local_ptr.rs index 813ea0f30f3..c94e5c6187b 100644 --- a/src/librustrt/local_ptr.rs +++ b/src/librustrt/local_ptr.rs @@ -20,7 +20,7 @@ use core::prelude::*; use core::mem; -use alloc::owned::Box; +use alloc::boxed::Box; #[cfg(windows)] // mingw-w32 doesn't like thread_local things #[cfg(target_os = "android")] // see #10686 @@ -86,7 +86,7 @@ pub unsafe fn borrow() -> Borrowed { pub mod compiled { use core::prelude::*; - use alloc::owned::Box; + use alloc::boxed::Box; use core::mem; #[cfg(test)] @@ -237,7 +237,7 @@ pub unsafe fn try_unsafe_borrow() -> Option<*mut T> { pub mod native { use core::prelude::*; - use alloc::owned::Box; + use alloc::boxed::Box; use core::mem; use core::ptr; use tls = thread_local_storage; diff --git a/src/librustrt/rtio.rs b/src/librustrt/rtio.rs index 7a91cca6265..343b911fb83 100644 --- a/src/librustrt/rtio.rs +++ b/src/librustrt/rtio.rs @@ -11,7 +11,7 @@ //! The EventLoop and internal synchronous I/O interface. use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use collections::string::String; use collections::vec::Vec; use core::fmt; diff --git a/src/librustrt/stack.rs b/src/librustrt/stack.rs index 8e637207d22..0eacd40f01c 100644 --- a/src/librustrt/stack.rs +++ b/src/librustrt/stack.rs @@ -56,7 +56,7 @@ #[lang = "stack_exhausted"] extern fn stack_exhausted() { use core::prelude::*; - use alloc::owned::Box; + use alloc::boxed::Box; use local::Local; use task::Task; use core::intrinsics; diff --git a/src/librustrt/task.rs b/src/librustrt/task.rs index 59401a8b666..78c32889277 100644 --- a/src/librustrt/task.rs +++ b/src/librustrt/task.rs @@ -16,7 +16,7 @@ use core::prelude::*; use alloc::arc::Arc; -use alloc::owned::{AnyOwnExt, Box}; +use alloc::boxed::{BoxAny, Box}; use core::any::Any; use core::atomics::{AtomicUint, SeqCst}; use core::iter::Take; @@ -376,7 +376,7 @@ pub fn maybe_take_runtime(&mut self) -> Option> { unsafe { let imp = self.imp.take_unwrap(); let vtable = mem::transmute::<_, &raw::TraitObject>(&imp).vtable; - match imp.wrap().move::() { + match imp.wrap().downcast::() { Ok(t) => Some(t), Err(t) => { let data = mem::transmute::<_, raw::TraitObject>(t).data; diff --git a/src/librustrt/thread.rs b/src/librustrt/thread.rs index 59784328cdb..7bc991cf72f 100644 --- a/src/librustrt/thread.rs +++ b/src/librustrt/thread.rs @@ -18,7 +18,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::mem; use core::uint; use libc; @@ -147,7 +147,7 @@ fn drop(&mut self) { mod imp { use core::prelude::*; - use alloc::owned::Box; + use alloc::boxed::Box; use core::cmp; use core::mem; use core::ptr; @@ -215,7 +215,7 @@ fn CreateThread(lpThreadAttributes: LPSECURITY_ATTRIBUTES, mod imp { use core::prelude::*; - use alloc::owned::Box; + use alloc::boxed::Box; use core::cmp; use core::mem; use core::ptr; diff --git a/src/librustrt/unwind.rs b/src/librustrt/unwind.rs index 18688cbcc64..f26cccdd3ed 100644 --- a/src/librustrt/unwind.rs +++ b/src/librustrt/unwind.rs @@ -59,7 +59,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use collections::string::String; use collections::vec::Vec; use core::any::Any; diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index a02402271d0..45301737adb 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -45,7 +45,7 @@ use mem; use ops::Drop; use option::{Some, None, Option}; -use owned::Box; +use boxed::Box; use ptr; use result::{Ok, Err}; diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs index 47ff85e2806..8c709d20d19 100644 --- a/src/libstd/failure.rs +++ b/src/libstd/failure.rs @@ -10,7 +10,7 @@ #![experimental] -use alloc::owned::Box; +use alloc::boxed::Box; use any::{Any, AnyRefExt}; use fmt; use io::{Writer, IoResult}; diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index ed183cbf3bc..ff2b35160a1 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -62,7 +62,7 @@ use kinds::Send; use libc; use option::{Some, None, Option}; -use owned::Box; +use boxed::Box; use path::{Path, GenericPath}; use path; use result::{Err, Ok}; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 4ef2e51fcf0..db4df7a8a6f 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -229,7 +229,7 @@ fn file_product(p: &Path) -> IoResult { use ops::{BitOr, BitAnd, Sub, Not}; use option::{Option, Some, None}; use os; -use owned::Box; +use boxed::Box; use result::{Ok, Err, Result}; use rt::rtio; use slice::{Vector, MutableVector, ImmutableVector}; diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 49322098348..642654ba6ed 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -29,7 +29,7 @@ use from_str::FromStr; use kinds::Send; use option::{None, Some, Option}; -use owned::Box; +use boxed::Box; use rt::rtio::{IoFactory, LocalIo, RtioSocket, RtioTcpListener}; use rt::rtio::{RtioTcpAcceptor, RtioTcpStream}; use rt::rtio; diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 21903eb2643..5f7563e7467 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -19,7 +19,7 @@ use io::net::ip::{SocketAddr, IpAddr}; use io::{Reader, Writer, IoResult, IoError}; use kinds::Send; -use owned::Box; +use boxed::Box; use option::Option; use result::{Ok, Err}; use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, LocalIo}; diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs index c5ddda9945d..5e7c4214977 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -30,7 +30,7 @@ use clone::Clone; use io::{Listener, Acceptor, Reader, Writer, IoResult, IoError}; use kinds::Send; -use owned::Box; +use boxed::Box; use rt::rtio::{IoFactory, LocalIo, RtioUnixListener}; use rt::rtio::{RtioUnixAcceptor, RtioPipe}; diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index a968f41a915..c476a99fee9 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -20,7 +20,7 @@ use io::{IoResult, IoError}; use libc; use os; -use owned::Box; +use boxed::Box; use rt::rtio::{RtioPipe, LocalIo}; /// A synchronous, in-memory pipe. diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 6ef73023779..07574b72645 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -21,7 +21,7 @@ use io; use libc; use mem; -use owned::Box; +use boxed::Box; use rt::rtio::{RtioProcess, ProcessConfig, IoFactory, LocalIo}; use rt::rtio; use c_str::CString; diff --git a/src/libstd/io/signal.rs b/src/libstd/io/signal.rs index 4a7655a63ce..d46f437cddd 100644 --- a/src/libstd/io/signal.rs +++ b/src/libstd/io/signal.rs @@ -26,7 +26,7 @@ use kinds::Send; use mem::drop; use option::{Some, None}; -use owned::Box; +use boxed::Box; use result::{Ok, Err}; use rt::rtio::{IoFactory, LocalIo, RtioSignal, Callback}; use slice::ImmutableVector; diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index cdd083202e0..45c084b3459 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -35,7 +35,7 @@ use kinds::Send; use libc; use option::{Option, Some, None}; -use owned::Box; +use boxed::Box; use result::{Ok, Err}; use rt; use rt::local::Local; diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index 432461c4606..1c9e428dcad 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -20,7 +20,7 @@ use comm::{Receiver, Sender, channel}; use io::{IoResult, IoError}; use kinds::Send; -use owned::Box; +use boxed::Box; use rt::rtio::{IoFactory, LocalIo, RtioTimer, Callback}; /// A synchronous timer object diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 2acf12b76c0..e928323030c 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -13,7 +13,7 @@ use prelude::*; use cmp; use io; -use owned::Box; +use boxed::Box; use slice::bytes::MutableByteVector; /// Wraps a `Reader`, limiting the number of bytes that can be read from it. @@ -263,7 +263,7 @@ fn read(&mut self, buf: &mut [u8]) -> io::IoResult { mod test { use io::{MemReader, MemWriter, BufReader}; use io; - use owned::Box; + use boxed::Box; use super::*; use prelude::*; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 14782cafce3..34c1530f96c 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -138,7 +138,7 @@ #[cfg(test)] pub use realstd::ops; #[cfg(test)] pub use realstd::cmp; #[cfg(test)] pub use realstd::ty; -#[cfg(test)] pub use realstd::owned; +#[cfg(test)] pub use realstd::boxed; #[cfg(test)] pub use realstd::gc; @@ -167,7 +167,10 @@ pub use core::result; pub use core::option; -pub use alloc::owned; +pub use alloc::boxed; +#[deprecated = "use boxed instead"] +pub use owned = boxed; + pub use alloc::rc; pub use core_collections::slice; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 21f80777293..a20ac112ac5 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -72,7 +72,7 @@ #[doc(no_inline)] pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; #[doc(no_inline)] pub use num::{Signed, Unsigned, Primitive, Int, Float}; #[doc(no_inline)] pub use num::{FloatMath, ToPrimitive, FromPrimitive}; -#[doc(no_inline)] pub use owned::Box; +#[doc(no_inline)] pub use boxed::Box; #[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath}; #[doc(no_inline)] pub use ptr::RawPtr; #[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek}; diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 72cc596085e..d7af92024eb 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -98,7 +98,7 @@ use io::{Writer, stdio}; use kinds::{Send, marker}; use option::{None, Some, Option}; -use owned::Box; +use boxed::Box; use result::Result; use rt::local::Local; use rt::task; @@ -374,7 +374,7 @@ pub fn failing() -> bool { #[cfg(test)] mod test { use any::{Any, AnyRefExt}; - use owned::AnyOwnExt; + use boxed::BoxAny; use result; use result::{Ok, Err}; use str::StrAllocating; @@ -578,7 +578,7 @@ fn test_try_fail_message_static_str() { Err(e) => { type T = &'static str; assert!(e.is::()); - assert_eq!(*e.move::().unwrap(), "static string"); + assert_eq!(*e.downcast::().unwrap(), "static string"); } Ok(()) => fail!() } @@ -592,7 +592,7 @@ fn test_try_fail_message_owned_str() { Err(e) => { type T = String; assert!(e.is::()); - assert_eq!(*e.move::().unwrap(), "owned string".to_string()); + assert_eq!(*e.downcast::().unwrap(), "owned string".to_string()); } Ok(()) => fail!() } @@ -606,9 +606,9 @@ fn test_try_fail_message_any() { Err(e) => { type T = Box; assert!(e.is::()); - let any = e.move::().unwrap(); + let any = e.downcast::().unwrap(); assert!(any.is::()); - assert_eq!(*any.move::().unwrap(), 413u16); + assert_eq!(*any.downcast::().unwrap(), 413u16); } Ok(()) => fail!() } diff --git a/src/libsync/atomics.rs b/src/libsync/atomics.rs index 195efb844a7..0be124ad584 100644 --- a/src/libsync/atomics.rs +++ b/src/libsync/atomics.rs @@ -103,7 +103,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::mem; pub use core::atomics::{AtomicBool, AtomicInt, AtomicUint, AtomicPtr}; diff --git a/src/libsync/comm/mod.rs b/src/libsync/comm/mod.rs index 6c09a021c43..e9a303634fe 100644 --- a/src/libsync/comm/mod.rs +++ b/src/libsync/comm/mod.rs @@ -320,7 +320,7 @@ use core::prelude::*; use alloc::arc::Arc; -use alloc::owned::Box; +use alloc::boxed::Box; use core::cell::Cell; use core::kinds::marker; use core::mem; diff --git a/src/libsync/comm/oneshot.rs b/src/libsync/comm/oneshot.rs index 742686069e2..c9782db5c24 100644 --- a/src/libsync/comm/oneshot.rs +++ b/src/libsync/comm/oneshot.rs @@ -34,7 +34,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::mem; use rustrt::local::Local; use rustrt::task::{Task, BlockedTask}; diff --git a/src/libsync/comm/select.rs b/src/libsync/comm/select.rs index 230bca624f5..737a4bfe299 100644 --- a/src/libsync/comm/select.rs +++ b/src/libsync/comm/select.rs @@ -54,7 +54,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::cell::Cell; use core::kinds::marker; use core::mem; diff --git a/src/libsync/comm/shared.rs b/src/libsync/comm/shared.rs index 5ad4dea5d2a..d13b2c32978 100644 --- a/src/libsync/comm/shared.rs +++ b/src/libsync/comm/shared.rs @@ -20,7 +20,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::cmp; use core::int; use rustrt::local::Local; diff --git a/src/libsync/comm/stream.rs b/src/libsync/comm/stream.rs index 6f337f17309..9747c207a22 100644 --- a/src/libsync/comm/stream.rs +++ b/src/libsync/comm/stream.rs @@ -19,7 +19,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::cmp; use core::int; use rustrt::local::Local; diff --git a/src/libsync/comm/sync.rs b/src/libsync/comm/sync.rs index 4d54df2fc19..cc3c2197c13 100644 --- a/src/libsync/comm/sync.rs +++ b/src/libsync/comm/sync.rs @@ -35,7 +35,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use collections::Vec; use collections::Collection; use core::mem; diff --git a/src/libsync/deque.rs b/src/libsync/deque.rs index 8d2192aeb53..913a58010d4 100644 --- a/src/libsync/deque.rs +++ b/src/libsync/deque.rs @@ -54,7 +54,7 @@ use alloc::arc::Arc; use alloc::heap::{allocate, deallocate}; -use alloc::owned::Box; +use alloc::boxed::Box; use collections::Vec; use core::kinds::marker; use core::mem::{forget, min_align_of, size_of, transmute}; diff --git a/src/libsync/mpsc_queue.rs b/src/libsync/mpsc_queue.rs index ecd37e68880..759695fe5b6 100644 --- a/src/libsync/mpsc_queue.rs +++ b/src/libsync/mpsc_queue.rs @@ -42,7 +42,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::mem; use core::ty::Unsafe; diff --git a/src/libsync/mutex.rs b/src/libsync/mutex.rs index a10ec745869..990d743465d 100644 --- a/src/libsync/mutex.rs +++ b/src/libsync/mutex.rs @@ -59,7 +59,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::atomics; use core::kinds::marker; use core::mem; diff --git a/src/libsync/spsc_queue.rs b/src/libsync/spsc_queue.rs index 2834d404c18..cf4d3222ed0 100644 --- a/src/libsync/spsc_queue.rs +++ b/src/libsync/spsc_queue.rs @@ -37,7 +37,7 @@ use core::prelude::*; -use alloc::owned::Box; +use alloc::boxed::Box; use core::mem; use core::ty::Unsafe; diff --git a/src/test/compile-fail/new-box-syntax-bad.rs b/src/test/compile-fail/new-box-syntax-bad.rs index 383a0ac4619..602ffe2680b 100644 --- a/src/test/compile-fail/new-box-syntax-bad.rs +++ b/src/test/compile-fail/new-box-syntax-bad.rs @@ -14,7 +14,7 @@ // Tests that the new `box` syntax works with unique pointers and GC pointers. use std::gc::{Gc, GC}; -use std::owned::{Box, HEAP}; +use std::boxed::{Box, HEAP}; pub fn main() { let x: Gc = box(HEAP) 2; //~ ERROR mismatched types diff --git a/src/test/run-pass/new-box-syntax.rs b/src/test/run-pass/new-box-syntax.rs index b16bef3fc99..f61a8837e2c 100644 --- a/src/test/run-pass/new-box-syntax.rs +++ b/src/test/run-pass/new-box-syntax.rs @@ -14,7 +14,7 @@ // Tests that the new `box` syntax works with unique pointers and GC pointers. use std::gc::{Gc, GC}; -use std::owned::{Box, HEAP}; +use std::boxed::{Box, HEAP}; struct Structure { x: int, @@ -33,4 +33,3 @@ pub fn main() { let c = box()(3i + 4); let d = box(GC)(5i + 6); } - diff --git a/src/test/run-pass/unit-like-struct-drop-run.rs b/src/test/run-pass/unit-like-struct-drop-run.rs index ae4623c6e66..3a1cc0331a3 100644 --- a/src/test/run-pass/unit-like-struct-drop-run.rs +++ b/src/test/run-pass/unit-like-struct-drop-run.rs @@ -10,7 +10,7 @@ // Make sure the destructor is run for unit-like structs. -use std::owned::AnyOwnExt; +use std::boxed::BoxAny; use std::task; struct Foo; @@ -26,6 +26,6 @@ pub fn main() { let _b = Foo; }); - let s = x.unwrap_err().move::<&'static str>().unwrap(); + let s = x.unwrap_err().downcast::<&'static str>().unwrap(); assert_eq!(s.as_slice(), "This failure should happen."); } -- 2.44.0