auto merge of #15591 : aturon/rust/box-cell-stability, r=alexcrichton
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]
This commit is contained in:
commit
ffd9966c79
@ -16,7 +16,6 @@ use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
|
||||
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 @@ use core::result::{Ok, Err, Result};
|
||||
///
|
||||
/// 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<T>(*mut T);
|
||||
|
||||
impl<T: Default> Default for Box<T> {
|
||||
@ -57,7 +58,6 @@ impl<T: Clone> Clone for Box<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// box pointers
|
||||
impl<T:PartialEq> PartialEq for Box<T> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) }
|
||||
@ -85,15 +85,22 @@ impl<T: Ord> Ord for Box<T> {
|
||||
impl<T: Eq> Eq for Box<T> {}
|
||||
|
||||
/// Extension methods for an owning `Any` trait object
|
||||
pub trait AnyOwnExt {
|
||||
#[unstable = "post-DST, the signature of `downcast` will change to take `Box<Self>`"]
|
||||
pub trait BoxAny {
|
||||
/// Returns the boxed value if it is of type `T`, or
|
||||
/// `Err(Self)` if it isn't.
|
||||
fn move<T: 'static>(self) -> Result<Box<T>, Self>;
|
||||
fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
|
||||
|
||||
/// Deprecated; this method has been renamed to `downcast`.
|
||||
#[deprecated = "use downcast instead"]
|
||||
fn move<T: 'static>(self) -> Result<Box<T>, Self> {
|
||||
self.downcast::<T>()
|
||||
}
|
||||
}
|
||||
|
||||
impl AnyOwnExt for Box<Any> {
|
||||
impl BoxAny for Box<Any> {
|
||||
#[inline]
|
||||
fn move<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
|
||||
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
|
||||
if self.is::<T>() {
|
||||
unsafe {
|
||||
// Get the raw representation of the trait object
|
||||
@ -112,34 +119,6 @@ impl AnyOwnExt for Box<Any> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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<T: 'static>(self) -> Result<Box<T>, Self>;
|
||||
}
|
||||
|
||||
impl AnySendOwnExt for Box<Any+Send> {
|
||||
#[inline]
|
||||
fn move_send<T: 'static>(self) -> Result<Box<T>, Box<Any+Send>> {
|
||||
if self.is::<T>() {
|
||||
unsafe {
|
||||
// Get the raw representation of the trait object
|
||||
let to: TraitObject =
|
||||
*mem::transmute::<&Box<Any+Send>, &TraitObject>(&self);
|
||||
|
||||
// Prevent destructor on self being run
|
||||
intrinsics::forget(self);
|
||||
|
||||
// Extract the data pointer
|
||||
Ok(mem::transmute(to.data))
|
||||
}
|
||||
} else {
|
||||
Err(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: fmt::Show> fmt::Show for Box<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
(**self).fmt(f)
|
||||
@ -166,11 +145,11 @@ mod test {
|
||||
let a = box 8u as Box<Any>;
|
||||
let b = box Test as Box<Any>;
|
||||
|
||||
match a.move::<uint>() {
|
||||
match a.downcast::<uint>() {
|
||||
Ok(a) => { assert!(a == box 8u); }
|
||||
Err(..) => fail!()
|
||||
}
|
||||
match b.move::<Test>() {
|
||||
match b.downcast::<Test>() {
|
||||
Ok(a) => { assert!(a == box Test); }
|
||||
Err(..) => fail!()
|
||||
}
|
||||
@ -178,8 +157,8 @@ mod test {
|
||||
let a = box 8u as Box<Any>;
|
||||
let b = box Test as Box<Any>;
|
||||
|
||||
assert!(a.move::<Box<Test>>().is_err());
|
||||
assert!(b.move::<Box<uint>>().is_err());
|
||||
assert!(a.downcast::<Box<Test>>().is_err());
|
||||
assert!(b.downcast::<Box<uint>>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
@ -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 @@ extern crate libc;
|
||||
#[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 @@ pub mod util;
|
||||
// Primitive types using the heaps above
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub mod owned;
|
||||
pub mod boxed;
|
||||
pub mod arc;
|
||||
pub mod rc;
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use core::fmt;
|
||||
use core::fmt::Show;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -163,11 +163,13 @@ use option::{None, Option, Some};
|
||||
use ty::Unsafe;
|
||||
|
||||
/// A mutable memory location that admits only `Copy` data.
|
||||
#[unstable = "likely to be renamed; otherwise stable"]
|
||||
pub struct Cell<T> {
|
||||
value: Unsafe<T>,
|
||||
noshare: marker::NoShare,
|
||||
}
|
||||
|
||||
#[stable]
|
||||
impl<T:Copy> Cell<T> {
|
||||
/// Creates a new `Cell` containing the given value.
|
||||
pub fn new(value: T) -> Cell<T> {
|
||||
@ -192,13 +194,14 @@ impl<T:Copy> Cell<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable]
|
||||
#[unstable = "waiting for `Clone` trait to become stable"]
|
||||
impl<T:Copy> Clone for Cell<T> {
|
||||
fn clone(&self) -> Cell<T> {
|
||||
Cell::new(self.get())
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting for `PartialEq` trait to become stable"]
|
||||
impl<T:PartialEq + Copy> PartialEq for Cell<T> {
|
||||
fn eq(&self, other: &Cell<T>) -> bool {
|
||||
self.get() == other.get()
|
||||
@ -206,6 +209,7 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
|
||||
}
|
||||
|
||||
/// A mutable memory location with dynamically checked borrow rules
|
||||
#[unstable = "likely to be renamed; otherwise stable"]
|
||||
pub struct RefCell<T> {
|
||||
value: Unsafe<T>,
|
||||
borrow: Cell<BorrowFlag>,
|
||||
@ -221,6 +225,7 @@ static WRITING: BorrowFlag = -1;
|
||||
|
||||
impl<T> RefCell<T> {
|
||||
/// Create a new `RefCell` containing `value`
|
||||
#[stable]
|
||||
pub fn new(value: T) -> RefCell<T> {
|
||||
RefCell {
|
||||
value: Unsafe::new(value),
|
||||
@ -231,6 +236,7 @@ impl<T> RefCell<T> {
|
||||
}
|
||||
|
||||
/// 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 @@ impl<T> RefCell<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<Ref<'a, T>> {
|
||||
match self.borrow.get() {
|
||||
WRITING => None,
|
||||
@ -260,6 +267,7 @@ impl<T> RefCell<T> {
|
||||
/// # 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 @@ impl<T> RefCell<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<RefMut<'a, T>> {
|
||||
match self.borrow.get() {
|
||||
UNUSED => {
|
||||
@ -291,6 +300,7 @@ impl<T> RefCell<T> {
|
||||
/// # 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 @@ impl<T> RefCell<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable]
|
||||
#[unstable = "waiting for `Clone` to become stable"]
|
||||
impl<T: Clone> Clone for RefCell<T> {
|
||||
fn clone(&self) -> RefCell<T> {
|
||||
RefCell::new(self.borrow().clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting for `PartialEq` to become stable"]
|
||||
impl<T: PartialEq> PartialEq for RefCell<T> {
|
||||
fn eq(&self, other: &RefCell<T>) -> bool {
|
||||
*self.borrow() == *other.borrow()
|
||||
@ -313,6 +324,7 @@ impl<T: PartialEq> PartialEq for RefCell<T> {
|
||||
}
|
||||
|
||||
/// 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 @@ impl<'b, T> Drop for Ref<'b, T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting for `Deref` to become stable"]
|
||||
impl<'b, T> Deref<T> for Ref<'b, T> {
|
||||
#[inline]
|
||||
fn deref<'a>(&'a self) -> &'a T {
|
||||
@ -341,7 +355,7 @@ impl<'b, T> Deref<T> for Ref<'b, 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 @@ impl<'b, T> Drop for RefMut<'b, T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting for `Deref` to become stable"]
|
||||
impl<'b, T> Deref<T> for RefMut<'b, T> {
|
||||
#[inline]
|
||||
fn deref<'a>(&'a self) -> &'a T {
|
||||
@ -377,6 +394,7 @@ impl<'b, T> Deref<T> for RefMut<'b, T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable = "waiting for `DerefMut` to become stable"]
|
||||
impl<'b, T> DerefMut<T> for RefMut<'b, T> {
|
||||
#[inline]
|
||||
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
|
||||
|
@ -45,7 +45,7 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { 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;
|
||||
|
@ -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;
|
||||
|
@ -37,7 +37,7 @@ pub use self::unwind::{begin_unwind, begin_unwind_fmt};
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use core::any::Any;
|
||||
|
||||
use task::{Task, BlockedTask, TaskOpts};
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use local_ptr;
|
||||
use task::Task;
|
||||
|
||||
|
@ -40,7 +40,7 @@ assert_eq!(*key_vector.get().unwrap(), vec![4]);
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use collections::vec::Vec;
|
||||
use core::kinds::marker;
|
||||
use core::mem;
|
||||
|
@ -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<T>() -> Borrowed<T> {
|
||||
pub mod compiled {
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use core::mem;
|
||||
|
||||
#[cfg(test)]
|
||||
@ -237,7 +237,7 @@ pub mod compiled {
|
||||
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;
|
||||
|
@ -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;
|
||||
|
@ -56,7 +56,7 @@ pub static RED_ZONE: uint = 20 * 1024;
|
||||
#[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;
|
||||
|
@ -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 @@ impl Task {
|
||||
unsafe {
|
||||
let imp = self.imp.take_unwrap();
|
||||
let vtable = mem::transmute::<_, &raw::TraitObject>(&imp).vtable;
|
||||
match imp.wrap().move::<T>() {
|
||||
match imp.wrap().downcast::<T>() {
|
||||
Ok(t) => Some(t),
|
||||
Err(t) => {
|
||||
let data = mem::transmute::<_, raw::TraitObject>(t).data;
|
||||
|
@ -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 @@ impl<T: Send> Drop for Thread<T> {
|
||||
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 @@ mod imp {
|
||||
mod imp {
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use core::cmp;
|
||||
use core::mem;
|
||||
use core::ptr;
|
||||
|
@ -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;
|
||||
|
@ -45,7 +45,7 @@ use iter::{range, Iterator};
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Some, None, Option};
|
||||
use owned::Box;
|
||||
use boxed::Box;
|
||||
use ptr;
|
||||
use result::{Ok, Err};
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#![experimental]
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use any::{Any, AnyRefExt};
|
||||
use fmt;
|
||||
use io::{Writer, IoResult};
|
||||
|
@ -62,7 +62,7 @@ use iter::Iterator;
|
||||
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};
|
||||
|
@ -229,7 +229,7 @@ use mem::transmute;
|
||||
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};
|
||||
|
@ -29,7 +29,7 @@ use io::{Reader, Writer, Listener, Acceptor};
|
||||
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;
|
||||
|
@ -19,7 +19,7 @@ use clone::Clone;
|
||||
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};
|
||||
|
@ -30,7 +30,7 @@ use c_str::ToCStr;
|
||||
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};
|
||||
|
||||
|
@ -20,7 +20,7 @@ use prelude::*;
|
||||
use io::{IoResult, IoError};
|
||||
use libc;
|
||||
use os;
|
||||
use owned::Box;
|
||||
use boxed::Box;
|
||||
use rt::rtio::{RtioPipe, LocalIo};
|
||||
|
||||
/// A synchronous, in-memory pipe.
|
||||
|
@ -21,7 +21,7 @@ use io::{IoResult, IoError};
|
||||
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;
|
||||
|
@ -26,7 +26,7 @@ use iter::Iterator;
|
||||
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;
|
||||
|
@ -35,7 +35,7 @@ use iter::Iterator;
|
||||
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;
|
||||
|
@ -20,7 +20,7 @@ and create receivers which will receive notifications after a period of time.
|
||||
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
|
||||
|
@ -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 @@ impl<T: Iterator<u8>> Reader for IterReader<T> {
|
||||
mod test {
|
||||
use io::{MemReader, MemWriter, BufReader};
|
||||
use io;
|
||||
use owned::Box;
|
||||
use boxed::Box;
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
|
||||
|
@ -138,7 +138,7 @@ extern crate rustrt;
|
||||
#[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::unit;
|
||||
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;
|
||||
|
@ -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};
|
||||
|
@ -98,7 +98,7 @@ use comm::channel;
|
||||
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 @@ mod test {
|
||||
Err(e) => {
|
||||
type T = &'static str;
|
||||
assert!(e.is::<T>());
|
||||
assert_eq!(*e.move::<T>().unwrap(), "static string");
|
||||
assert_eq!(*e.downcast::<T>().unwrap(), "static string");
|
||||
}
|
||||
Ok(()) => fail!()
|
||||
}
|
||||
@ -592,7 +592,7 @@ mod test {
|
||||
Err(e) => {
|
||||
type T = String;
|
||||
assert!(e.is::<T>());
|
||||
assert_eq!(*e.move::<T>().unwrap(), "owned string".to_string());
|
||||
assert_eq!(*e.downcast::<T>().unwrap(), "owned string".to_string());
|
||||
}
|
||||
Ok(()) => fail!()
|
||||
}
|
||||
@ -606,9 +606,9 @@ mod test {
|
||||
Err(e) => {
|
||||
type T = Box<Any + Send>;
|
||||
assert!(e.is::<T>());
|
||||
let any = e.move::<T>().unwrap();
|
||||
let any = e.downcast::<T>().unwrap();
|
||||
assert!(any.is::<u16>());
|
||||
assert_eq!(*any.move::<u16>().unwrap(), 413u16);
|
||||
assert_eq!(*any.downcast::<u16>().unwrap(), 413u16);
|
||||
}
|
||||
Ok(()) => fail!()
|
||||
}
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use collections::Vec;
|
||||
use collections::Collection;
|
||||
use core::mem;
|
||||
|
@ -54,7 +54,7 @@ use core::prelude::*;
|
||||
|
||||
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};
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use core::mem;
|
||||
use core::ty::Unsafe;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use alloc::owned::Box;
|
||||
use alloc::boxed::Box;
|
||||
use core::mem;
|
||||
use core::ty::Unsafe;
|
||||
|
||||
|
@ -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<int> = box(HEAP) 2; //~ ERROR mismatched types
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user