diff options
| author | bors <bors@rust-lang.org> | 2017-02-07 17:28:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-02-07 17:28:51 +0000 |
| commit | a797b6e2feb1c6cd60868a2d3b59029a0ca5df64 (patch) | |
| tree | f487614a9344ef2e1e86980bafe9c2844dd61279 | |
| parent | c49d10207a7e105525fb3bd71c18fde6fc2f5aed (diff) | |
| parent | 0cc2448e053047546aff4ea0749adb06896092b5 (diff) | |
| download | rust-a797b6e2feb1c6cd60868a2d3b59029a0ca5df64.tar.gz rust-a797b6e2feb1c6cd60868a2d3b59029a0ca5df64.zip | |
Auto merge of #39002 - GuillaumeGomez:debug_libcollections, r=aturon
Add Debug implementations for libcollection structs Part of #31869.
| -rw-r--r-- | src/libcollections/binary_heap.rs | 39 | ||||
| -rw-r--r-- | src/libcollections/btree/map.rs | 52 | ||||
| -rw-r--r-- | src/libcollections/btree/set.rs | 47 | ||||
| -rw-r--r-- | src/libcollections/enum_set.rs | 8 | ||||
| -rw-r--r-- | src/libcollections/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcollections/linked_list.rs | 49 | ||||
| -rw-r--r-- | src/libcollections/str.rs | 8 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 7 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 10 | ||||
| -rw-r--r-- | src/libcollections/vec_deque.rs | 36 |
10 files changed, 257 insertions, 0 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 23e0295ba54..a5a2f70492d 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -228,6 +228,15 @@ pub struct PeekMut<'a, T: 'a + Ord> { sift: bool, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: Ord + fmt::Debug> fmt::Debug for PeekMut<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("PeekMut") + .field(&self.heap.data[0]) + .finish() + } +} + #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] impl<'a, T: Ord> Drop for PeekMut<'a, T> { fn drop(&mut self) { @@ -968,6 +977,15 @@ pub struct Iter<'a, T: 'a> { iter: slice::Iter<'a, T>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Iter") + .field(&self.iter.as_slice()) + .finish() + } +} + // FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Clone for Iter<'a, T> { @@ -1016,6 +1034,15 @@ pub struct IntoIter<T> { iter: vec::IntoIter<T>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("IntoIter") + .field(&self.iter.as_slice()) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T> Iterator for IntoIter<T> { type Item = T; @@ -1051,6 +1078,7 @@ impl<T> FusedIterator for IntoIter<T> {} /// An iterator that drains a `BinaryHeap`. #[stable(feature = "drain", since = "1.6.0")] +#[derive(Debug)] pub struct Drain<'a, T: 'a> { iter: vec::Drain<'a, T>, } @@ -1203,6 +1231,17 @@ where T: Clone + Ord { #[unstable(feature = "collection_placement", reason = "placement protocol is subject to change", issue = "30172")] +impl<'a, T: Clone + Ord + fmt::Debug> fmt::Debug for BinaryHeapPlace<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("BinaryHeapPlace") + .field(&self.place) + .finish() + } +} + +#[unstable(feature = "collection_placement", + reason = "placement protocol is subject to change", + issue = "30172")] impl<'a, T: 'a> Placer<T> for &'a mut BinaryHeap<T> where T: Clone + Ord { type Place = BinaryHeapPlace<'a, T>; diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 4755f8a4c55..e1fabe2cc49 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -270,8 +270,16 @@ pub struct Iter<'a, K: 'a, V: 'a> { length: usize, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Iter<'a, K, V> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list().entries(self.clone()).finish() + } +} + /// A mutable iterator over a BTreeMap's entries. #[stable(feature = "rust1", since = "1.0.0")] +#[derive(Debug)] pub struct IterMut<'a, K: 'a, V: 'a> { range: RangeMut<'a, K, V>, length: usize, @@ -285,20 +293,46 @@ pub struct IntoIter<K, V> { length: usize, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let range = Range { + front: self.front.reborrow(), + back: self.back.reborrow(), + }; + f.debug_list().entries(range).finish() + } +} + /// An iterator over a BTreeMap's keys. #[stable(feature = "rust1", since = "1.0.0")] pub struct Keys<'a, K: 'a, V: 'a> { inner: Iter<'a, K, V>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Keys<'a, K, V> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list().entries(self.inner.clone()).finish() + } +} + /// An iterator over a BTreeMap's values. #[stable(feature = "rust1", since = "1.0.0")] pub struct Values<'a, K: 'a, V: 'a> { inner: Iter<'a, K, V>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Values<'a, K, V> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list().entries(self.inner.clone()).finish() + } +} + /// A mutable iterator over a BTreeMap's values. #[stable(feature = "map_values_mut", since = "1.10.0")] +#[derive(Debug)] pub struct ValuesMut<'a, K: 'a, V: 'a> { inner: IterMut<'a, K, V>, } @@ -309,6 +343,13 @@ pub struct Range<'a, K: 'a, V: 'a> { back: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Range<'a, K, V> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list().entries(self.clone()).finish() + } +} + /// A mutable iterator over a sub-range of BTreeMap's entries. pub struct RangeMut<'a, K: 'a, V: 'a> { front: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>, @@ -318,6 +359,17 @@ pub struct RangeMut<'a, K: 'a, V: 'a> { _marker: PhantomData<&'a mut (K, V)>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for RangeMut<'a, K, V> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let range = Range { + front: self.front.reborrow(), + back: self.back.reborrow(), + }; + f.debug_list().entries(range).finish() + } +} + /// A view into a single entry in a map, which may either be vacant or occupied. /// This enum is constructed from the [`entry`] method on [`BTreeMap`]. /// diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index f006ba95371..bfffa0b8efa 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -85,6 +85,15 @@ pub struct Iter<'a, T: 'a> { iter: Keys<'a, T, ()>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Iter") + .field(&self.iter.clone()) + .finish() + } +} + /// An owning iterator over a `BTreeSet`'s items. /// /// This structure is created by the `into_iter` method on [`BTreeSet`] @@ -92,6 +101,7 @@ pub struct Iter<'a, T: 'a> { /// /// [`BTreeSet`]: struct.BTreeSet.html #[stable(feature = "rust1", since = "1.0.0")] +#[derive(Debug)] pub struct IntoIter<T> { iter: ::btree_map::IntoIter<T, ()>, } @@ -102,6 +112,7 @@ pub struct IntoIter<T> { /// /// [`BTreeSet`]: struct.BTreeSet.html /// [`range`]: struct.BTreeSet.html#method.range +#[derive(Debug)] pub struct Range<'a, T: 'a> { iter: ::btree_map::Range<'a, T, ()>, } @@ -118,6 +129,15 @@ pub struct Difference<'a, T: 'a> { b: Peekable<Iter<'a, T>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Difference<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Difference") + .field(&self.clone()) + .finish() + } +} + /// A lazy iterator producing elements in the set symmetric difference (in-order). /// /// This structure is created by the [`symmetric_difference`] method on @@ -131,6 +151,15 @@ pub struct SymmetricDifference<'a, T: 'a> { b: Peekable<Iter<'a, T>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for SymmetricDifference<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("SymmetricDifference") + .field(&self.clone()) + .finish() + } +} + /// A lazy iterator producing elements in the set intersection (in-order). /// /// This structure is created by the [`intersection`] method on [`BTreeSet`]. @@ -143,6 +172,15 @@ pub struct Intersection<'a, T: 'a> { b: Peekable<Iter<'a, T>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Intersection<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Intersection") + .field(&self.clone()) + .finish() + } +} + /// A lazy iterator producing elements in the set union (in-order). /// /// This structure is created by the [`union`] method on [`BTreeSet`]. @@ -155,6 +193,15 @@ pub struct Union<'a, T: 'a> { b: Peekable<Iter<'a, T>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Union<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Union") + .field(&self.clone()) + .finish() + } +} + impl<T: Ord> BTreeSet<T> { /// Makes a new `BTreeSet` with a reasonable choice of B. /// diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 78b61079777..602e874aaee 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -222,6 +222,14 @@ pub struct Iter<E> { marker: marker::PhantomData<E>, } +impl<E: fmt::Debug> fmt::Debug for Iter<E> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Iter") + .field(&self.clone()) + .finish() + } +} + // FIXME(#19839) Remove in favor of `#[derive(Clone)]` impl<E> Clone for Iter<E> { fn clone(&self) -> Iter<E> { diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 39de87c0840..53d5466e12b 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -28,6 +28,7 @@ #![cfg_attr(test, allow(deprecated))] // rand #![deny(warnings)] +#![deny(missing_debug_implementations)] #![feature(alloc)] #![feature(allow_internal_unstable)] diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index 7f913d4afe4..d4f77d625b3 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -65,6 +65,15 @@ pub struct Iter<'a, T: 'a> { marker: PhantomData<&'a Node<T>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Iter") + .field(&self.clone()) + .finish() + } +} + // FIXME #19839: deriving is too aggressive on the bounds (T doesn't need to be Clone). #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Clone for Iter<'a, T> { @@ -82,6 +91,15 @@ pub struct IterMut<'a, T: 'a> { len: usize, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("IterMut") + .field(self.clone()) + .finish() + } +} + /// An iterator over the elements of a `LinkedList`. #[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] @@ -89,6 +107,15 @@ pub struct IntoIter<T> { list: LinkedList<T>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("IntoIter") + .field(self.clone()) + .finish() + } +} + impl<T> Node<T> { fn new(element: T) -> Self { Node { @@ -1078,6 +1105,17 @@ pub struct FrontPlace<'a, T: 'a> { } #[unstable(feature = "collection_placement", + reason = "struct name and placement protocol are subject to change", + issue = "30172")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for FrontPlace<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("FrontPlace") + .field(self.clone()) + .finish() + } +} + +#[unstable(feature = "collection_placement", reason = "placement protocol is subject to change", issue = "30172")] impl<'a, T> Placer<T> for FrontPlace<'a, T> { @@ -1122,6 +1160,17 @@ pub struct BackPlace<'a, T: 'a> { } #[unstable(feature = "collection_placement", + reason = "struct name and placement protocol are subject to change", + issue = "30172")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for BackPlace<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("BackPlace") + .field(self.clone()) + .finish() + } +} + +#[unstable(feature = "collection_placement", reason = "placement protocol is subject to change", issue = "30172")] impl<'a, T> Placer<T> for BackPlace<'a, T> { diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 458d5114829..87315fff0a0 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -19,6 +19,7 @@ // It's cleaner to just turn off the unused_imports warning than to fix them. #![allow(unused_imports)] +use core::fmt; use core::str as core_str; use core::str::pattern::Pattern; use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher}; @@ -122,6 +123,13 @@ pub struct EncodeUtf16<'a> { encoder: Utf16Encoder<Chars<'a>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a> fmt::Debug for EncodeUtf16<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("EncodeUtf16 { .. }") + } +} + #[stable(feature = "encode_utf16", since = "1.8.0")] impl<'a> Iterator for EncodeUtf16<'a> { type Item = u16; diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 9a985061ebb..4c82e2e2e7e 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1990,6 +1990,13 @@ pub struct Drain<'a> { iter: Chars<'a>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a> fmt::Debug for Drain<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Drain { .. }") + } +} + #[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a> Sync for Drain<'a> {} #[stable(feature = "drain", since = "1.6.0")] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index c45518438bd..dc0f33d9bc3 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2089,6 +2089,15 @@ pub struct Drain<'a, T: 'a> { vec: Shared<Vec<T>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Drain") + .field(&self.iter.as_slice()) + .finish() + } +} + #[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {} #[stable(feature = "drain", since = "1.6.0")] @@ -2155,6 +2164,7 @@ impl<'a, T> FusedIterator for Drain<'a, T> {} #[unstable(feature = "collection_placement", reason = "struct name and placement protocol are subject to change", issue = "30172")] +#[derive(Debug)] pub struct PlaceBack<'a, T: 'a> { vec: &'a mut Vec<T>, } diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 5e1adb3d808..8d42045ff16 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -1856,6 +1856,15 @@ pub struct Iter<'a, T: 'a> { head: usize, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Iter") + .field(&self.clone()) + .finish() + } +} + // FIXME(#19839) Remove in favor of `#[derive(Clone)]` #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Clone for Iter<'a, T> { @@ -1928,6 +1937,15 @@ pub struct IterMut<'a, T: 'a> { head: usize, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("IterMut") + .field(&self.clone()) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Iterator for IterMut<'a, T> { type Item = &'a mut T; @@ -1994,6 +2012,15 @@ pub struct IntoIter<T> { inner: VecDeque<T>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("IntoIter") + .field(&self.clone()) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<T> Iterator for IntoIter<T> { type Item = T; @@ -2037,6 +2064,15 @@ pub struct Drain<'a, T: 'a> { deque: Shared<VecDeque<T>>, } +#[stable(feature = "collection_debug", since = "1.17.0")] +impl<'a, T: 'a + fmt::Debug> fmt::Debug for Drain<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("Drain") + .field(&self.clone()) + .finish() + } +} + #[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {} #[stable(feature = "drain", since = "1.6.0")] |
