-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Debug implementations for libcollection structs #39002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
61fbdbb
ba841f0
668af80
0cc2448
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,15 @@ pub struct PeekMut<'a, T: 'a + Ord> { | |
sift: bool, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To match the others, should this not be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to refer to the struct used to create the iterator rather than the path of the iterator. |
||
.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.15.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("BinaryHeap::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.15.0")] | ||
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("BinaryHeap::IntoIter") | ||
.field(&self.iter.as_slice()) | ||
.finish() | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T> Iterator for IntoIter<T> { | ||
type Item = T; | ||
|
@@ -1055,6 +1082,15 @@ pub struct Drain<'a, T: 'a> { | |
iter: vec::Drain<'a, T>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.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("BinaryHeap::Drain") | ||
.field(&self.iter) | ||
.finish() | ||
} | ||
} | ||
|
||
#[stable(feature = "drain", since = "1.6.0")] | ||
impl<'a, T: 'a> Iterator for Drain<'a, T> { | ||
type Item = T; | ||
|
@@ -1200,6 +1236,15 @@ where T: Clone + Ord { | |
place: vec::PlaceBack<'a, T>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.0")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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) | ||
.finish() | ||
} | ||
} | ||
|
||
#[unstable(feature = "collection_placement", | ||
reason = "placement protocol is subject to change", | ||
issue = "30172")] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,15 @@ pub struct Iter<'a, T: 'a> { | |
iter: Keys<'a, T, ()>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.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("BTreeSet::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`] | ||
|
@@ -96,6 +105,13 @@ pub struct IntoIter<T> { | |
iter: ::btree_map::IntoIter<T, ()>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.0")] | ||
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.pad(&format!("BTreeSet::IntoIter({:?})", self.iter)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's still intermediate strings here (and in other places) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll do a pass for the missing ones. Sorry about this. |
||
} | ||
} | ||
|
||
/// An iterator over a sub-range of `BTreeSet`'s items. | ||
/// | ||
/// This structure is created by the [`range`] method on [`BTreeSet`]. | ||
|
@@ -106,6 +122,13 @@ pub struct Range<'a, T: 'a> { | |
iter: ::btree_map::Range<'a, T, ()>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.0")] | ||
impl<'a, T: 'a + fmt::Debug> fmt::Debug for Range<'a, T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.pad(&format!("BTreeSet::Range({:?})", self.iter)) | ||
} | ||
} | ||
|
||
/// A lazy iterator producing elements in the set difference (in-order). | ||
/// | ||
/// This structure is created by the [`difference`] method on [`BTreeSet`]. | ||
|
@@ -118,6 +141,15 @@ pub struct Difference<'a, T: 'a> { | |
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.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("BTreeSet::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 +163,15 @@ pub struct SymmetricDifference<'a, T: 'a> { | |
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.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("BTreeSet::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 +184,15 @@ pub struct Intersection<'a, T: 'a> { | |
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.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("BTreeSet::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 +205,15 @@ pub struct Union<'a, T: 'a> { | |
b: Peekable<Iter<'a, T>>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.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("BTreeSet::Union") | ||
.field(&self.clone()) | ||
.finish() | ||
} | ||
} | ||
|
||
impl<T: Ord> BTreeSet<T> { | ||
/// Makes a new `BTreeSet` with a reasonable choice of B. | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,15 @@ pub struct Iter<E> { | |
marker: marker::PhantomData<E>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.15.0")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
impl<E: fmt::Debug> fmt::Debug for Iter<E> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("EnumSet::Iter") | ||
.field(&self.clone()) | ||
.finish() | ||
} | ||
} | ||
|
||
// FIXME(#19839) Remove in favor of `#[derive(Clone)]` | ||
impl<E> Clone for Iter<E> { | ||
fn clone(&self) -> Iter<E> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should all be
"1.16.0"
.