about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-22 06:12:46 +0000
committerbors <bors@rust-lang.org>2015-01-22 06:12:46 +0000
commit5d2056a7e3e52b2aec41662cfd960e0eafe8494c (patch)
tree24169c2dc6be5e6c80f6bc3549fb83714160723f /src/liballoc
parent6869645e86c91544b8737b89809bdf10bef536d9 (diff)
parent90af72378d9f848de78adc5003dff6b90f327b3c (diff)
downloadrust-5d2056a7e3e52b2aec41662cfd960e0eafe8494c.tar.gz
rust-5d2056a7e3e52b2aec41662cfd960e0eafe8494c.zip
Auto merge of #21473 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs13
-rw-r--r--src/liballoc/boxed.rs76
-rw-r--r--src/liballoc/boxed_test.rs75
-rw-r--r--src/liballoc/heap.rs2
-rw-r--r--src/liballoc/lib.rs4
-rw-r--r--src/liballoc/rc.rs170
6 files changed, 118 insertions, 222 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index c0cd034abfa..5f8cd6baf9a 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -72,7 +72,7 @@ use core::prelude::*;
 use core::atomic;
 use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
 use core::borrow::BorrowFrom;
-use core::fmt::{self, Show};
+use core::fmt;
 use core::cmp::{Ordering};
 use core::default::Default;
 use core::mem::{min_align_of, size_of};
@@ -578,16 +578,17 @@ impl<T: Ord> Ord for Arc<T> {
 #[stable]
 impl<T: Eq> Eq for Arc<T> {}
 
-impl<T: fmt::Show> fmt::Show for Arc<T> {
+#[stable]
+impl<T: fmt::Display> fmt::Display for Arc<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "Arc({:?})", (**self))
+        fmt::Display::fmt(&**self, f)
     }
 }
 
 #[stable]
-impl<T: fmt::String> fmt::String for Arc<T> {
+impl<T: fmt::Debug> fmt::Debug for Arc<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        fmt::String::fmt(&**self, f)
+        fmt::Debug::fmt(&**self, f)
     }
 }
 
@@ -806,7 +807,7 @@ mod tests {
     #[test]
     fn show_arc() {
         let a = Arc::new(5u32);
-        assert!(format!("{:?}", a) == "Arc(5u32)")
+        assert_eq!(format!("{:?}", a), "5");
     }
 
     // Make sure deriving works with Arc<T>
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index a2cc98c7d01..5ec08a1f254 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -16,16 +16,18 @@ use core::any::Any;
 use core::clone::Clone;
 use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
 use core::default::Default;
+use core::error::{Error, FromError};
 use core::fmt;
 use core::hash::{self, Hash};
+use core::iter::Iterator;
 use core::marker::Sized;
 use core::mem;
+use core::ops::{Deref, DerefMut};
 use core::option::Option;
 use core::ptr::Unique;
 use core::raw::TraitObject;
-use core::result::Result;
 use core::result::Result::{Ok, Err};
-use core::ops::{Deref, DerefMut};
+use core::result::Result;
 
 /// A value that represents the global exchange heap. This is the default
 /// place that the `box` keyword allocates into when no place is supplied.
@@ -156,20 +158,22 @@ impl BoxAny for Box<Any> {
     }
 }
 
-impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> {
+#[stable]
+impl<T: fmt::Display + ?Sized> fmt::Display for Box<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "Box({:?})", &**self)
+        fmt::Display::fmt(&**self, f)
     }
 }
 
 #[stable]
-impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
+impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        fmt::String::fmt(&**self, f)
+        fmt::Debug::fmt(&**self, f)
     }
 }
 
-impl fmt::Show for Box<Any> {
+#[stable]
+impl fmt::Debug for Box<Any> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.pad("Box<Any>")
     }
@@ -187,56 +191,22 @@ impl<T: ?Sized> DerefMut for Box<T> {
     fn deref_mut(&mut self) -> &mut T { &mut **self }
 }
 
-#[cfg(test)]
-mod test {
-    #[test]
-    fn test_owned_clone() {
-        let a = Box::new(5i);
-        let b: Box<int> = a.clone();
-        assert!(a == b);
-    }
+// FIXME(#21363) remove `old_impl_check` when bug is fixed
+#[old_impl_check]
+impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> {
+    type Item = T;
 
-    #[test]
-    fn any_move() {
-        let a = Box::new(8u) as Box<Any>;
-        let b = Box::new(Test) as Box<Any>;
-
-        match a.downcast::<uint>() {
-            Ok(a) => { assert!(a == Box::new(8u)); }
-            Err(..) => panic!()
-        }
-        match b.downcast::<Test>() {
-            Ok(a) => { assert!(a == Box::new(Test)); }
-            Err(..) => panic!()
-        }
-
-        let a = Box::new(8u) as Box<Any>;
-        let b = Box::new(Test) as Box<Any>;
-
-        assert!(a.downcast::<Box<Test>>().is_err());
-        assert!(b.downcast::<Box<uint>>().is_err());
+    fn next(&mut self) -> Option<T> {
+        (**self).next()
     }
 
-    #[test]
-    fn test_show() {
-        let a = Box::new(8u) as Box<Any>;
-        let b = Box::new(Test) as Box<Any>;
-        let a_str = a.to_str();
-        let b_str = b.to_str();
-        assert_eq!(a_str, "Box<Any>");
-        assert_eq!(b_str, "Box<Any>");
-
-        let a = &8u as &Any;
-        let b = &Test as &Any;
-        let s = format!("{}", a);
-        assert_eq!(s, "&Any");
-        let s = format!("{}", b);
-        assert_eq!(s, "&Any");
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        (**self).size_hint()
     }
+}
 
-    #[test]
-    fn deref() {
-        fn homura<T: Deref<Target=i32>>(_: T) { }
-        homura(Box::new(765i32));
+impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> {
+    fn from_error(err: E) -> Box<Error + 'a> {
+        Box::new(err)
     }
 }
diff --git a/src/liballoc/boxed_test.rs b/src/liballoc/boxed_test.rs
new file mode 100644
index 00000000000..c47a771f60d
--- /dev/null
+++ b/src/liballoc/boxed_test.rs
@@ -0,0 +1,75 @@
+// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Test for `boxed` mod.
+
+use core::any::Any;
+use core::ops::Deref;
+use core::result::Result::{Ok, Err};
+use core::clone::Clone;
+
+use std::boxed::Box;
+use std::boxed::BoxAny;
+
+#[test]
+fn test_owned_clone() {
+    let a = Box::new(5i);
+    let b: Box<int> = a.clone();
+    assert!(a == b);
+}
+
+#[derive(PartialEq, Eq)]
+struct Test;
+
+#[test]
+fn any_move() {
+    let a = Box::new(8u) as Box<Any>;
+    let b = Box::new(Test) as Box<Any>;
+
+    match a.downcast::<uint>() {
+        Ok(a) => { assert!(a == Box::new(8u)); }
+        Err(..) => panic!()
+    }
+    match b.downcast::<Test>() {
+        Ok(a) => { assert!(a == Box::new(Test)); }
+        Err(..) => panic!()
+    }
+
+    let a = Box::new(8u) as Box<Any>;
+    let b = Box::new(Test) as Box<Any>;
+
+    assert!(a.downcast::<Box<Test>>().is_err());
+    assert!(b.downcast::<Box<uint>>().is_err());
+}
+
+#[test]
+fn test_show() {
+    let a = Box::new(8u) as Box<Any>;
+    let b = Box::new(Test) as Box<Any>;
+    let a_str = format!("{:?}", a);
+    let b_str = format!("{:?}", b);
+    assert_eq!(a_str, "Box<Any>");
+    assert_eq!(b_str, "Box<Any>");
+
+    static EIGHT: usize = 8us;
+    static TEST: Test = Test;
+    let a = &EIGHT as &Any;
+    let b = &TEST as &Any;
+    let s = format!("{:?}", a);
+    assert_eq!(s, "&Any");
+    let s = format!("{:?}", b);
+    assert_eq!(s, "&Any");
+}
+
+#[test]
+fn deref() {
+    fn homura<T: Deref<Target=i32>>(_: T) { }
+    homura(Box::new(765i32));
+}
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs
index bd5b43b782e..a2643f4d0f7 100644
--- a/src/liballoc/heap.rs
+++ b/src/liballoc/heap.rs
@@ -280,7 +280,7 @@ mod imp {
         if align <= MIN_ALIGN {
             libc::malloc(size as libc::size_t) as *mut u8
         } else {
-            let mut out = 0 as *mut libc::c_void;
+            let mut out = ptr::null_mut();
             let ret = posix_memalign(&mut out,
                                      align as libc::size_t,
                                      size as libc::size_t);
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 811e32e747d..231ef6e7e74 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -70,6 +70,8 @@
 #![feature(lang_items, unsafe_destructor)]
 #![feature(box_syntax)]
 #![feature(optin_builtin_traits)]
+// FIXME(#21363) remove `old_impl_check` when bug is fixed
+#![feature(old_impl_check)]
 #![allow(unknown_features)] #![feature(int_uint)]
 
 #[macro_use]
@@ -91,6 +93,8 @@ pub mod heap;
 
 #[cfg(not(test))]
 pub mod boxed;
+#[cfg(test)]
+mod boxed_test;
 pub mod arc;
 pub mod rc;
 
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 7191a7af346..5e82c4f1ade 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -174,61 +174,17 @@ struct RcBox<T> {
 /// See the [module level documentation](../index.html) for more details.
 #[unsafe_no_drop_flag]
 #[stable]
-#[cfg(stage0)] // NOTE remove impl after next snapshot
 pub struct Rc<T> {
     // FIXME #12808: strange names to try to avoid interfering with field accesses of the contained
     // type via Deref
     _ptr: NonZero<*mut RcBox<T>>,
-    _nosend: marker::NoSend,
-    _noshare: marker::NoSync
 }
 
-/// An immutable reference-counted pointer type.
-///
-/// See the [module level documentation](../index.html) for more details.
-#[unsafe_no_drop_flag]
-#[stable]
-#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
-pub struct Rc<T> {
-    // FIXME #12808: strange names to try to avoid interfering with field accesses of the contained
-    // type via Deref
-    _ptr: NonZero<*mut RcBox<T>>,
-}
-
-#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
 impl<T> !marker::Send for Rc<T> {}
 
-#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
 impl<T> !marker::Sync for Rc<T> {}
 
 impl<T> Rc<T> {
-    /// Constructs a new `Rc<T>`.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// use std::rc::Rc;
-    ///
-    /// let five = Rc::new(5i);
-    /// ```
-    #[stable]
-    #[cfg(stage0)] // NOTE remove after next snapshot
-    pub fn new(value: T) -> Rc<T> {
-        unsafe {
-            Rc {
-                // 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 {
-                    value: value,
-                    strong: Cell::new(1),
-                    weak: Cell::new(1)
-                })),
-                _nosend: marker::NoSend,
-                _noshare: marker::NoSync
-            }
-        }
-    }
 
     /// Constructs a new `Rc<T>`.
     ///
@@ -240,7 +196,6 @@ impl<T> Rc<T> {
     /// let five = Rc::new(5i);
     /// ```
     #[stable]
-    #[cfg(not(stage0))] // NOTE remove cfg after next snapshot
     pub fn new(value: T) -> Rc<T> {
         unsafe {
             Rc {
@@ -267,29 +222,6 @@ impl<T> Rc<T> {
     ///
     /// let weak_five = five.downgrade();
     /// ```
-    #[cfg(stage0)] // NOTE remove after next snapshot
-    #[unstable = "Weak pointers may not belong in this module"]
-    pub fn downgrade(&self) -> Weak<T> {
-        self.inc_weak();
-        Weak {
-            _ptr: self._ptr,
-            _nosend: marker::NoSend,
-            _noshare: marker::NoSync
-        }
-    }
-
-    /// Downgrades the `Rc<T>` to a `Weak<T>` reference.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// use std::rc::Rc;
-    ///
-    /// let five = Rc::new(5i);
-    ///
-    /// let weak_five = five.downgrade();
-    /// ```
-    #[cfg(not(stage0))] // NOTE remove cfg after next snapshot
     #[unstable = "Weak pointers may not belong in this module"]
     pub fn downgrade(&self) -> Weak<T> {
         self.inc_weak();
@@ -483,25 +415,6 @@ impl<T> Drop for Rc<T> {
 
 #[stable]
 impl<T> Clone for Rc<T> {
-    /// Makes a clone of the `Rc<T>`.
-    ///
-    /// This increases the strong reference count.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// use std::rc::Rc;
-    ///
-    /// let five = Rc::new(5i);
-    ///
-    /// five.clone();
-    /// ```
-    #[inline]
-    #[cfg(stage0)] // NOTE remove after next snapshot
-    fn clone(&self) -> Rc<T> {
-        self.inc_strong();
-        Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
-    }
 
     /// Makes a clone of the `Rc<T>`.
     ///
@@ -517,7 +430,6 @@ impl<T> Clone for Rc<T> {
     /// five.clone();
     /// ```
     #[inline]
-    #[cfg(not(stage0))] // NOTE remove cfg after next snapshot
     fn clone(&self) -> Rc<T> {
         self.inc_strong();
         Rc { _ptr: self._ptr }
@@ -693,17 +605,17 @@ impl<S: hash::Hasher, T: Hash<S>> Hash<S> for Rc<T> {
     }
 }
 
-#[unstable = "Show is experimental."]
-impl<T: fmt::Show> fmt::Show for Rc<T> {
+#[stable]
+impl<T: fmt::Display> fmt::Display for Rc<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "Rc({:?})", **self)
+        fmt::Display::fmt(&**self, f)
     }
 }
 
 #[stable]
-impl<T: fmt::String> fmt::String for Rc<T> {
+impl<T: fmt::Debug> fmt::Debug for Rc<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        fmt::String::fmt(&**self, f)
+        fmt::Debug::fmt(&**self, f)
     }
 }
 
@@ -714,66 +626,21 @@ impl<T: fmt::String> fmt::String for Rc<T> {
 /// See the [module level documentation](../index.html) for more.
 #[unsafe_no_drop_flag]
 #[unstable = "Weak pointers may not belong in this module."]
-#[cfg(stage0)] // NOTE remove impl after next snapshot
 pub struct Weak<T> {
     // FIXME #12808: strange names to try to avoid interfering with
     // field accesses of the contained type via Deref
     _ptr: NonZero<*mut RcBox<T>>,
-    _nosend: marker::NoSend,
-    _noshare: marker::NoSync
 }
 
-/// A weak version of `Rc<T>`.
-///
-/// Weak references do not count when determining if the inner value should be dropped.
-///
-/// See the [module level documentation](../index.html) for more.
-#[unsafe_no_drop_flag]
-#[unstable = "Weak pointers may not belong in this module."]
-#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
-pub struct Weak<T> {
-    // FIXME #12808: strange names to try to avoid interfering with
-    // field accesses of the contained type via Deref
-    _ptr: NonZero<*mut RcBox<T>>,
-}
-
-#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
 #[allow(unstable)]
 impl<T> !marker::Send for Weak<T> {}
 
-#[cfg(not(stage0))] // NOTE remove cfg after next snapshot
 #[allow(unstable)]
 impl<T> !marker::Sync for Weak<T> {}
 
 
 #[unstable = "Weak pointers may not belong in this module."]
 impl<T> Weak<T> {
-    /// Upgrades a weak reference to a strong reference.
-    ///
-    /// Upgrades the `Weak<T>` reference to an `Rc<T>`, if possible.
-    ///
-    /// Returns `None` if there were no strong references and the data was destroyed.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// use std::rc::Rc;
-    ///
-    /// let five = Rc::new(5i);
-    ///
-    /// let weak_five = five.downgrade();
-    ///
-    /// let strong_five: Option<Rc<_>> = weak_five.upgrade();
-    /// ```
-    #[cfg(stage0)] // NOTE remove after next snapshot
-    pub fn upgrade(&self) -> Option<Rc<T>> {
-        if self.strong() == 0 {
-            None
-        } else {
-            self.inc_strong();
-            Some(Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync })
-        }
-    }
 
     /// Upgrades a weak reference to a strong reference.
     ///
@@ -792,7 +659,6 @@ impl<T> Weak<T> {
     ///
     /// let strong_five: Option<Rc<_>> = weak_five.upgrade();
     /// ```
-    #[cfg(not(stage0))] // NOTE remove cfg after next snapshot
     pub fn upgrade(&self) -> Option<Rc<T>> {
         if self.strong() == 0 {
             None
@@ -849,25 +715,6 @@ impl<T> Drop for Weak<T> {
 
 #[unstable = "Weak pointers may not belong in this module."]
 impl<T> Clone for Weak<T> {
-    /// Makes a clone of the `Weak<T>`.
-    ///
-    /// This increases the weak reference count.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// use std::rc::Rc;
-    ///
-    /// let weak_five = Rc::new(5i).downgrade();
-    ///
-    /// weak_five.clone();
-    /// ```
-    #[inline]
-    #[cfg(stage0)] // NOTE remove after next snapshot
-    fn clone(&self) -> Weak<T> {
-        self.inc_weak();
-        Weak { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
-    }
 
     /// Makes a clone of the `Weak<T>`.
     ///
@@ -883,15 +730,14 @@ impl<T> Clone for Weak<T> {
     /// weak_five.clone();
     /// ```
     #[inline]
-    #[cfg(not(stage0))] // NOTE remove cfg after next snapshot
     fn clone(&self) -> Weak<T> {
         self.inc_weak();
         Weak { _ptr: self._ptr }
     }
 }
 
-#[unstable = "Show is experimental."]
-impl<T: fmt::Show> fmt::Show for Weak<T> {
+#[stable]
+impl<T: fmt::Debug> fmt::Debug for Weak<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "(Weak)")
     }
@@ -1134,7 +980,7 @@ mod tests {
     #[test]
     fn test_show() {
         let foo = Rc::new(75u);
-        assert!(format!("{:?}", foo) == "Rc(75u)")
+        assert_eq!(format!("{:?}", foo), "75");
     }
 
 }