diff options
| author | Brian Anderson <banderson@mozilla.com> | 2015-01-24 09:15:42 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2015-01-25 01:20:55 -0800 |
| commit | 63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70 (patch) | |
| tree | c732033c0822f25f2aebcdf193de1b257bac1855 /src/liballoc | |
| parent | b44ee371b8beea77aa1364460acbba14a8516559 (diff) | |
| parent | 0430a43d635841db44978bb648e9cf7e7cfa1bba (diff) | |
| download | rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.tar.gz rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.zip | |
Merge remote-tracking branch 'rust-lang/master'
Conflicts: mk/tests.mk src/liballoc/arc.rs src/liballoc/boxed.rs src/liballoc/rc.rs src/libcollections/bit.rs src/libcollections/btree/map.rs src/libcollections/btree/set.rs src/libcollections/dlist.rs src/libcollections/ring_buf.rs src/libcollections/slice.rs src/libcollections/str.rs src/libcollections/string.rs src/libcollections/vec.rs src/libcollections/vec_map.rs src/libcore/any.rs src/libcore/array.rs src/libcore/borrow.rs src/libcore/error.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/ops.rs src/libcore/result.rs src/libcore/slice.rs src/libcore/str/mod.rs src/libregex/lib.rs src/libregex/re.rs src/librustc/lint/builtin.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mutex.rs src/libstd/sync/poison.rs src/libstd/sync/rwlock.rs src/libsyntax/feature_gate.rs src/libsyntax/test.rs
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/arc.rs | 13 | ||||
| -rw-r--r-- | src/liballoc/boxed.rs | 155 | ||||
| -rw-r--r-- | src/liballoc/boxed_test.rs | 75 | ||||
| -rw-r--r-- | src/liballoc/heap.rs | 2 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 4 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 173 |
6 files changed, 186 insertions, 236 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index c8f568b07cb..1b75289c64f 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}; @@ -582,16 +582,17 @@ impl<T: Ord> Ord for Arc<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: Eq> Eq for Arc<T> {} -impl<T: fmt::Show> fmt::Show for Arc<T> { +#[stable(feature = "rust1", since = "1.0.0")] +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(feature = "rust1", since = "1.0.0")] -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) } } @@ -809,7 +810,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 19fa6771fb7..51e5fc5820c 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -8,7 +8,40 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! A unique pointer type. +//! A pointer type for heap allocation. +//! +//! `Box<T>`, casually referred to as a 'box', provides the simplest form of heap allocation in +//! Rust. Boxes provide ownership for this allocation, and drop their contents when they go out of +//! scope. +//! +//! Boxes are useful in two situations: recursive data structures, and occasionally when returning +//! data. [The Pointer chapter of the Book](../../../book/pointers.html#best-practices-1) explains +//! these cases in detail. +//! +//! # Examples +//! +//! Creating a box: +//! +//! ``` +//! let x = Box::new(5); +//! ``` +//! +//! Creating a recursive data structure: +//! +//! ``` +//! #[derive(Show)] +//! enum List<T> { +//! Cons(T, Box<List<T>>), +//! Nil, +//! } +//! +//! fn main() { +//! let list: List<i32> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil)))); +//! println!("{:?}", list); +//! } +//! ``` +//! +//! This will print `Cons(1i32, Box(Cons(2i32, Box(Nil))))`. #![stable(feature = "rust1", since = "1.0.0")] @@ -16,19 +49,21 @@ 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. +/// A value that represents the heap. This is the default place that the `box` keyword allocates +/// into when no place is supplied. /// /// The following two examples are equivalent: /// @@ -37,10 +72,8 @@ use core::ops::{Deref, DerefMut}; /// use std::boxed::HEAP; /// /// fn main() { -/// # struct Bar; -/// # impl Bar { fn new(_a: int) { } } -/// let foo = box(HEAP) Bar::new(2); -/// let foo = box Bar::new(2); +/// let foo = box(HEAP) 5; +/// let foo = box 5; /// } /// ``` #[lang = "exchange_heap"] @@ -48,13 +81,21 @@ use core::ops::{Deref, DerefMut}; reason = "may be renamed; uncertain about custom allocator design")] pub static HEAP: () = (); -/// A type that represents a uniquely-owned value. +/// A pointer type for heap allocation. +/// +/// See the [module-level documentation](../../std/boxed/index.html) for more. #[lang = "owned_box"] #[stable(feature = "rust1", since = "1.0.0")] pub struct Box<T>(Unique<T>); impl<T> Box<T> { - /// Moves `x` into a freshly allocated box on the global exchange heap. + /// Allocates memory on the heap and then moves `x` into it. + /// + /// # Examples + /// + /// ``` + /// let x = Box::new(5); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new(x: T) -> Box<T> { box x @@ -75,11 +116,29 @@ impl<T> Default for Box<[T]> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: Clone> Clone for Box<T> { - /// Returns a copy of the owned box. + /// Returns a new box with a `clone()` of this box's contents. + /// + /// # Examples + /// + /// ``` + /// let x = Box::new(5); + /// let y = x.clone(); + /// ``` #[inline] fn clone(&self) -> Box<T> { box {(**self).clone()} } - /// Performs copy-assignment from `source` by reusing the existing allocation. + /// Copies `source`'s contents into `self` without creating a new allocation. + /// + /// # Examples + /// + /// ``` + /// let x = Box::new(5); + /// let mut y = Box::new(10); + /// + /// y.clone_from(&x); + /// + /// assert_eq!(*y, 5); + /// ``` #[inline] fn clone_from(&mut self, source: &Box<T>) { (**self).clone_from(&(**source)); @@ -158,20 +217,22 @@ impl BoxAny for Box<Any> { } } -impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> { +#[stable(feature = "rust1", since = "1.0.0")] +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(feature = "rust1", since = "1.0.0")] -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(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for Box<Any> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("Box<Any>") } @@ -189,56 +250,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); - } - - #[test] - fn any_move() { - let a = Box::new(8u) as Box<Any>; - let b = Box::new(Test) as Box<Any>; +// 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; - 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 9a72d7d0510..dcbd4d57cf9 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 cadb8907cf8..6830a1c33df 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)] #![feature(core)] #![feature(hash)] @@ -94,6 +96,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 27153b12d87..d41673f56ed 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -173,32 +173,15 @@ struct RcBox<T> { /// /// See the [module level documentation](../index.html) for more details. #[unsafe_no_drop_flag] -#[cfg(stage0)] // NOTE remove impl after next snapshot #[stable(feature = "rust1", since = "1.0.0")] 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(feature = "rust1", since = "1.0.0")] -#[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> { @@ -211,36 +194,7 @@ impl<T> Rc<T> { /// /// let five = Rc::new(5i); /// ``` - #[cfg(stage0)] // NOTE remove after next snapshot - #[stable(feature = "rust1", since = "1.0.0")] - 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>`. - /// - /// # Examples - /// - /// ``` - /// use std::rc::Rc; - /// - /// let five = Rc::new(5i); - /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[cfg(not(stage0))] // NOTE remove cfg after next snapshot pub fn new(value: T) -> Rc<T> { unsafe { Rc { @@ -267,30 +221,6 @@ impl<T> Rc<T> { /// /// let weak_five = five.downgrade(); /// ``` - #[cfg(stage0)] // NOTE remove after next snapshot - #[unstable(feature = "alloc", - reason = "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(feature = "alloc", reason = "Weak pointers may not belong in this module")] pub fn downgrade(&self) -> Weak<T> { @@ -485,25 +415,6 @@ impl<T> Drop for Rc<T> { #[stable(feature = "rust1", since = "1.0.0")] 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>`. /// @@ -519,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 } @@ -695,17 +605,17 @@ impl<S: hash::Hasher, T: Hash<S>> Hash<S> for Rc<T> { } } -#[unstable(feature = "alloc", reason = "Show is experimental.")] -impl<T: fmt::Show> fmt::Show for Rc<T> { +#[stable(feature = "rust1", since = "1.0.0")] +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(feature = "rust1", since = "1.0.0")] -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) } } @@ -715,68 +625,22 @@ impl<T: fmt::String> fmt::String for Rc<T> { /// /// See the [module level documentation](../index.html) for more. #[unsafe_no_drop_flag] -#[cfg(stage0)] // NOTE remove impl after next snapshot -#[unstable(feature = "alloc", - reason = "Weak pointers may not belong in this module.")] -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(feature = "alloc", reason = "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 impl<T> !marker::Send for Weak<T> {} -#[cfg(not(stage0))] // NOTE remove cfg after next snapshot impl<T> !marker::Sync for Weak<T> {} #[unstable(feature = "alloc", reason = "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. /// @@ -795,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 @@ -853,25 +716,6 @@ impl<T> Drop for Weak<T> { #[unstable(feature = "alloc", reason = "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>`. /// @@ -887,15 +731,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(feature = "alloc", reason = "Show is experimental.")] -impl<T: fmt::Show> fmt::Show for Weak<T> { +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: fmt::Debug> fmt::Debug for Weak<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "(Weak)") } @@ -1137,7 +980,7 @@ mod tests { #[test] fn test_show() { let foo = Rc::new(75u); - assert!(format!("{:?}", foo) == "Rc(75u)") + assert_eq!(format!("{:?}", foo), "75"); } } |
