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

Implement Debug for std::path::{Components,Iter}. #36101

Merged
merged 2 commits into from
Aug 31, 2016

Conversation

frewsxcv
Copy link
Member

No description provided.

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let components = self.as_path()
.components()
.collect::<Vec<_>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shame to have to allocate on debug. You should be able to do this using debug_list and a helper struct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can switch this to debug_list to avoid the allocation, though we lose the "Components" title. I wonder if there is value in adding a debug_iter that offers name and iterator params.

Copy link
Contributor

@Stebalien Stebalien Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a helper struct that implements debug and outputs [...]. That is,

f.debug_tuple("Components").field(&DebugHelper(self)).finish();

where DebugHelper implements Debug.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Aug 29, 2016
@alexcrichton alexcrichton self-assigned this Aug 29, 2016
@alexcrichton
Copy link
Member

Thanks @frewsxcv! I wonder if perhaps the same implementation should be used for the other iterators in this module?

@frewsxcv frewsxcv changed the title Implement Debug for std::path::Components. Implement Debug for std::path::{Components,Iter}. Aug 30, 2016
@frewsxcv
Copy link
Member Author

Latest commits no longer allocate Vecs. I also implemented Debug for std::path::Iter.

@@ -639,6 +639,25 @@ pub struct Iter<'a> {
inner: Components<'a>,
}

#[stable(feature = "path_components_debug", since = "")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This since should be 1.13.0 I believe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the latest force push.

@alexcrichton
Copy link
Member

@bors: r+ e118d4c

@alexcrichton alexcrichton added the relnotes Marks issues that should be documented in the release notes of the next release. label Aug 30, 2016
@sophiajt
Copy link
Contributor

@bors rollup

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 30, 2016
…lexcrichton

Implement `Debug` for `std::path::{Components,Iter}`.

None
@sophiajt
Copy link
Contributor

sophiajt commented Aug 30, 2016

@bors r-

I'm seeing this failure on build_bot (auto-win-msvc-64-opt-rustbuild), and it seems related:

failures:
    path::tests::test_iter_debug

test result: FAILED. 736 passed; 1 failed; 4 ignored; 0 measured

If that's not related I can re-approve.

@frewsxcv
Copy link
Member Author

More info:

thread '<unnamed>' panicked at 'assertion failed: `(left == right)` (left: `"Iter([\"/\", \"tmp\"])"`, right: `"Iter([\"\\\\\", \"tmp\"])"`)', C:\bot\slave\auto-win-msvc-64-opt-rustbuild\build\src\libstd\path.rs:3554

I changed that test to only run on unix now.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Aug 31, 2016

📌 Commit 268b3f5 has been approved by alexcrichton

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 31, 2016
…lexcrichton

Implement `Debug` for `std::path::{Components,Iter}`.

None
sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 31, 2016
…lexcrichton

Implement `Debug` for `std::path::{Components,Iter}`.

None
bors added a commit that referenced this pull request Aug 31, 2016
@bors bors merged commit 268b3f5 into rust-lang:master Aug 31, 2016
@frewsxcv frewsxcv deleted the debug-path-components branch August 31, 2016 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants