-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add Debug implementations for libcollection structs #39002
Conversation
src/libcollections/binary_heap.rs
Outdated
#[stable(feature = "collection_debug", since = "1.15.0")] | ||
impl<'a, T: 'a> fmt::Debug for Iter<'a, T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.pad("BinaryHeap::Iter { .. }") |
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.
What's the plan here about showing the elements? It needs specialization to add the case for T: fmt::Debug
later, and I don't think we want the complexity of having both impls (without debug bound and with) for each struct.
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.
I kept the implementation as easy as possible. Also, why would it need an implementation for T: fmt::Debug
? Except if you want to see the internals, I'm not sure this is very useful.
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.
To identify the iterator with its sequence of elements seems like the logical thing (if it is easy to iterate the sequence from &self
). Like how [1, 2, 3].iter()
has a debug that shows Iter([1, 2, 3])
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.
I'll add it then.
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.
In this case, it'd require to consume self in order to see the values. I don't think we want this behavior.
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.
Why do you have to consume? Can't you iterate over self.iter.as_slice()
?
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.
It doesn't have such a method as far as I can tell, or maybe I missed it?
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.
/// `BinaryHeap` iterator.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> {
iter: slice::Iter<'a, T>,
}
https://doc.rust-lang.org/std/slice/struct.Iter.html#method.as_slice
9e29d1a
to
5b06afd
Compare
Updated. |
In my opinion, every |
I'll add others as well. |
640d50b
to
5dda7f7
Compare
Here's the |
5dda7f7
to
30691b9
Compare
Updated. No more commented impl. |
Why is specialization being used here? Is that being used elsewhere in |
FWIW, specialization is being used in the other PR you approved: #39156 Also, |
@alexcrichton: Is it an issue? Sounded like a good idea to me... |
@GuillaumeGomez yes we don't use specialization for these purposes, just performance in a few minor scenarios. These types should likely all require that generics all implement |
I removed specialization. |
src/libcollections/binary_heap.rs
Outdated
#[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.pad(&format!("PeekMut({:?})", self.heap.data[0])) |
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.
This should use the debug builders instead of allocating a string.
src/libcollections/binary_heap.rs
Outdated
#[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.pad(&format!("BinaryHeap::Drain({:?})", self.iter)) |
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.
Same as above with string allocation (and a number of instances below too)
25258cd
to
513532e
Compare
Updated (for the two given). |
513532e
to
668af80
Compare
A new struct has been added since I started this PR, it has its debug implementation as well. |
src/libcollections/vec.rs
Outdated
.field(&self.vec.as_slice()) | ||
.finish() | ||
} | ||
} |
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.
How come implementations like this aren't using #{derive(Debug)]
?
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.
The habit, didn't thought of testing it, my bad... However, once this PR merged, such cases won't happen again thanks to the corresponding deny option. ;)
src/libcollections/btree/set.rs
Outdated
#[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 comment
The 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 comment
The 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.
I removed all the |
src/libcollections/binary_heap.rs
Outdated
@@ -228,6 +228,15 @@ pub struct PeekMut<'a, T: 'a + Ord> { | |||
sift: bool, | |||
} | |||
|
|||
#[stable(feature = "collection_debug", since = "1.15.0")] |
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"
.
src/libcollections/binary_heap.rs
Outdated
#[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 comment
The reason will be displayed to describe this comment to others. Learn more.
To match the others, should this not be "BinaryHeap::PeekMut"
? Although it might be better to use part of the actual path like "binary_heap::PeekMut"
for all of these instead.
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.
I prefer to refer to the struct used to create the iterator rather than the path of the iterator.
src/libcollections/binary_heap.rs
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
BinaryHeapPlace
is unstable so this impl should get the same stability attribute as BinaryHeapPlace
.
src/libcollections/enum_set.rs
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
EnumSet
is unstable so this stability attribute should probably be removed.
src/libcollections/linked_list.rs
Outdated
@@ -1077,6 +1104,15 @@ pub struct FrontPlace<'a, T: 'a> { | |||
node: IntermediateBox<Node<T>>, | |||
} | |||
|
|||
#[stable(feature = "collection_debug", since = "1.15.0")] |
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.
Again FrontPlace
is unstable.
src/libcollections/linked_list.rs
Outdated
@@ -1121,6 +1157,15 @@ pub struct BackPlace<'a, T: 'a> { | |||
node: IntermediateBox<Node<T>>, | |||
} | |||
|
|||
#[stable(feature = "collection_debug", since = "1.15.0")] |
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.
Again BackPlace
is unstable.
d62f2b8
to
8daacb3
Compare
@ollie27: Thanks for your review! I think I fixed all of them (replacing |
src/libcollections/binary_heap.rs
Outdated
#[stable(feature = "collection_debug", since = "1.16.0")] | ||
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("BinaryHeap::IntoIter") |
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.
Currently the precedence for this is to not have the namespace prefix, so let's remove it.
src/libcollections/btree/set.rs
Outdated
#[stable(feature = "collection_debug", since = "1.16.0")] | ||
impl<T: fmt::Debug> fmt::Debug for IntoIter<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("BTreeSet::IntoIter") |
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.
This should also just be #[derive]
Note that when I point things out like this it's typically useful to go over the PR looking for other cases as well. I'll try to exhaustively point it out this time but only fixing precisely what is pointed out isn't always the best strategy.
src/libcollections/btree/set.rs
Outdated
#[stable(feature = "collection_debug", since = "1.16.0")] | ||
impl<'a, T: 'a + fmt::Debug> fmt::Debug for Range<'a, T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("BTreeSet::Range") |
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.
This should be a derive
src/libcollections/binary_heap.rs
Outdated
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) |
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.
This should be a derive
src/libcollections/binary_heap.rs
Outdated
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) |
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.
This is probably infinite recursion
src/libcollections/btree/map.rs
Outdated
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for IterMut<'a, K, V> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("BTreeMap::IterMut") | ||
.field(&self.range) |
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.
This should be a derive
src/libcollections/btree/map.rs
Outdated
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for ValuesMut<'a, K, V> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("BTreeMap::ValuesMut") | ||
.field(&self.inner) |
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.
This should be a derive
b6dd3f1
to
393c3e4
Compare
@alexcrichton: I think I addressed all your review comments. |
@rfcbot fcp merge |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
src/libcollections/binary_heap.rs
Outdated
@@ -228,6 +228,15 @@ pub struct PeekMut<'a, T: 'a + Ord> { | |||
sift: bool, | |||
} | |||
|
|||
#[stable(feature = "collection_debug", since = "1.16.0")] |
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.
I guess this missed 1.16 so these will need changing to 1.17 now.
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.
Indeed... Updating it.
393c3e4
to
0cc2448
Compare
Updated the release version number to 1.17. |
ping @brson |
@bors: r+ |
📌 Commit 0cc2448 has been approved by |
Add Debug implementations for libcollection structs Part of #31869.
☀️ Test successful - status-appveyor, status-travis |
Part of #31869.