Skip to content
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

Merged
merged 4 commits into from Feb 7, 2017

Conversation

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Jan 11, 2017

Part of #31869.

#[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 { .. }")

This comment has been minimized.

Copy link
@bluss

bluss Jan 11, 2017

Member

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.

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jan 12, 2017

Author Member

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.

This comment has been minimized.

Copy link
@bluss

bluss Jan 13, 2017

Member

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])

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jan 14, 2017

Author Member

I'll add it then.

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jan 15, 2017

Author Member

In this case, it'd require to consume self in order to see the values. I don't think we want this behavior.

This comment has been minimized.

Copy link
@frewsxcv

frewsxcv Jan 16, 2017

Member

Why do you have to consume? Can't you iterate over self.iter.as_slice()?

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jan 16, 2017

Author Member

It doesn't have such a method as far as I can tell, or maybe I missed it?

This comment has been minimized.

Copy link
@frewsxcv

frewsxcv Jan 16, 2017

Member
/// `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

@alexcrichton alexcrichton added the T-libs label Jan 11, 2017
@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch from 9e29d1a to 5b06afd Jan 16, 2017
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 16, 2017

Updated.

@frewsxcv

This comment has been minimized.

Copy link
Member

frewsxcv commented Jan 16, 2017

In my opinion, every impl here should display the Debug for all the items in the collection, not just BinaryHeap::Iter.

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 16, 2017

I'll add others as well.

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch 2 times, most recently from 640d50b to 5dda7f7 Jan 16, 2017
@frewsxcv

This comment has been minimized.

Copy link
Member

frewsxcv commented Jan 18, 2017

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch from 5dda7f7 to 30691b9 Jan 18, 2017
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 18, 2017

Updated. No more commented impl.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 19, 2017

Why is specialization being used here? Is that being used elsewhere in Debug implementations?

@alexcrichton alexcrichton self-assigned this Jan 19, 2017
@frewsxcv

This comment has been minimized.

Copy link
Member

frewsxcv commented Jan 19, 2017

Why is specialization being used here? Is that being used elsewhere in Debug implementations?

FWIW, specialization is being used in the other PR you approved: #39156

Also, rg "default fn fmt" does not return any results

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 19, 2017

@alexcrichton: Is it an issue? Sounded like a good idea to me...

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 19, 2017

@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 Debug to stay conservative for now.

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 20, 2017

I removed specialization.

#[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]))

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 20, 2017

Member

This should use the debug builders instead of allocating a string.

#[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))

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 20, 2017

Member

Same as above with string allocation (and a number of instances below too)

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch from 25258cd to 513532e Jan 20, 2017
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 20, 2017

Updated (for the two given).

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch from 513532e to 668af80 Jan 20, 2017
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 20, 2017

A new struct has been added since I started this PR, it has its debug implementation as well.

.field(&self.vec.as_slice())
.finish()
}
}

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 20, 2017

Member

How come implementations like this aren't using #{derive(Debug)]?

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jan 20, 2017

Author Member

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. ;)

#[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))

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 20, 2017

Member

There's still intermediate strings here (and in other places)

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jan 20, 2017

Author Member

Ok, I'll do a pass for the missing ones. Sorry about this.

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 20, 2017

I removed all the format and the PlaceBack struct is now directly deriving Debug. Do you see anything else @alexcrichton?

@@ -228,6 +228,15 @@ pub struct PeekMut<'a, T: 'a + Ord> {
sift: bool,
}

#[stable(feature = "collection_debug", since = "1.15.0")]

This comment has been minimized.

Copy link
@ollie27

ollie27 Jan 23, 2017

Contributor

These should all be "1.16.0".

#[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")

This comment has been minimized.

Copy link
@ollie27

ollie27 Jan 23, 2017

Contributor

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.

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jan 23, 2017

Author Member

I prefer to refer to the struct used to create the iterator rather than the path of the iterator.

@@ -1200,6 +1236,15 @@ where T: Clone + Ord {
place: vec::PlaceBack<'a, T>,
}

#[stable(feature = "collection_debug", since = "1.15.0")]

This comment has been minimized.

Copy link
@ollie27

ollie27 Jan 23, 2017

Contributor

BinaryHeapPlace is unstable so this impl should get the same stability attribute as BinaryHeapPlace.

@@ -220,6 +220,15 @@ pub struct Iter<E> {
marker: marker::PhantomData<E>,
}

#[stable(feature = "collection_debug", since = "1.15.0")]

This comment has been minimized.

Copy link
@ollie27

ollie27 Jan 23, 2017

Contributor

EnumSet is unstable so this stability attribute should probably be removed.

@@ -1077,6 +1104,15 @@ pub struct FrontPlace<'a, T: 'a> {
node: IntermediateBox<Node<T>>,
}

#[stable(feature = "collection_debug", since = "1.15.0")]

This comment has been minimized.

Copy link
@ollie27

ollie27 Jan 23, 2017

Contributor

Again FrontPlace is unstable.

@@ -1121,6 +1157,15 @@ pub struct BackPlace<'a, T: 'a> {
node: IntermediateBox<Node<T>>,
}

#[stable(feature = "collection_debug", since = "1.15.0")]

This comment has been minimized.

Copy link
@ollie27

ollie27 Jan 23, 2017

Contributor

Again BackPlace is unstable.

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch from d62f2b8 to 8daacb3 Jan 23, 2017
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 23, 2017

@ollie27: Thanks for your review! I think I fixed all of them (replacing 1.15 with 1.16 and removing/replacing stable when it was unstable).

#[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")

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 23, 2017

Member

Currently the precedence for this is to not have the namespace prefix, so let's remove it.

#[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")

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 23, 2017

Member

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.

#[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")

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 23, 2017

Member

This should be a derive

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)

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 23, 2017

Member

This should be a derive

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)

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 23, 2017

Member

This is probably infinite recursion

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)

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 23, 2017

Member

This should be a derive

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)

This comment has been minimized.

Copy link
@alexcrichton

alexcrichton Jan 23, 2017

Member

This should be a derive

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch 2 times, most recently from b6dd3f1 to 393c3e4 Jan 23, 2017
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Jan 23, 2017

@alexcrichton: I think I addressed all your review comments.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 24, 2017

@rfcbot fcp merge

@rfcbot

This comment has been minimized.

Copy link

rfcbot commented Jan 24, 2017

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.

@frewsxcv frewsxcv mentioned this pull request Jan 24, 2017
0 of 57 tasks complete
@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Feb 4, 2017

ping @sfackler and @brson (checkboxes)

@@ -228,6 +228,15 @@ pub struct PeekMut<'a, T: 'a + Ord> {
sift: bool,
}

#[stable(feature = "collection_debug", since = "1.16.0")]

This comment has been minimized.

Copy link
@ollie27

ollie27 Feb 4, 2017

Contributor

I guess this missed 1.16 so these will need changing to 1.17 now.

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Feb 5, 2017

Author Member

Indeed... Updating it.

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:debug_libcollections branch from 393c3e4 to 0cc2448 Feb 5, 2017
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Feb 5, 2017

Updated the release version number to 1.17.

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

GuillaumeGomez commented Feb 7, 2017

ping @brson

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Feb 7, 2017

@bors: r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 7, 2017

📌 Commit 0cc2448 has been approved by aturon

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 7, 2017

⌛️ Testing commit 0cc2448 with merge a797b6e...

bors added a commit that referenced this pull request Feb 7, 2017
Add Debug implementations for libcollection structs

Part of #31869.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 7, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: aturon
Pushing a797b6e to master...

@bors bors merged commit 0cc2448 into rust-lang:master Feb 7, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@GuillaumeGomez GuillaumeGomez deleted the GuillaumeGomez:debug_libcollections branch Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.