Skip to content

Fix escaping of chars in Debug for Wtf8 backed OsStr #27319

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

Merged
merged 1 commit into from
Jul 28, 2015
Merged

Fix escaping of chars in Debug for Wtf8 backed OsStr #27319

merged 1 commit into from
Jul 28, 2015

Conversation

diaphore
Copy link
Contributor

I had to modify some tests : since wtf8buf_show and wtf8_show were doing the exact same thing, I repurposed wtf8_show to wtf8buf_show_str which ensures Wtf8Buf Debug-formats the same as str.

write_str_escaped might also be shared amongst other fmt but I just left it there within Wtf8::fmt for review.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn write_str_escaped(f: &mut fmt::Formatter, s: &str) -> fmt::Result {
for c in s.chars().flat_map(|c| c.escape_default()) {
try!(write!(f, "{}", c))
Copy link
Member

Choose a reason for hiding this comment

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

I think we want this to just be try!(f.write_char(c)), it saves some indirections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That bit is verbatim from core::fmt. I tried write_char but it didn't work (was missing Write in scope) so I didn't touch the code. Fixing now.

@bluss
Copy link
Member

bluss commented Jul 27, 2015

Testcompiling some code suggests that using write_char results in some real code size improvements, i.e. the write version results in irremovable overhead. So the other instances of using write!(f, "{}", c) should probably be fixed.

#![crate_type="lib"]
use std::fmt::{self, Write};

pub fn test_write(c: char, f: &mut fmt::Formatter) -> fmt::Result {
    write!(f, "{}", c)
}

pub fn test_write_char(c: char, f: &mut fmt::Formatter) -> fmt::Result {
    f.write_char(c)
}

@alexcrichton
Copy link
Member

Looks like there are some errors with make tidy, but otherwise looks good to me, thanks!

@diaphore
Copy link
Contributor Author

I've got 2 instances of write! fixed in core::fmt, shall I include them in this PR ?

@alexcrichton
Copy link
Member

What do you mean by "fixed"? Also, could you squash the commits down?

@diaphore
Copy link
Contributor Author

@alexcrichton Changed 2 instances of write!(f, "{}", c) to f.write_char(c) : in impl Debug for str and impl Debug for str.

I'll try squashing ... it might all blow up.

@alexcrichton
Copy link
Member

Ah ok, that's fine to throw in as well

@brson brson assigned alexcrichton and unassigned brson Jul 27, 2015
Fixes #27211

Fix Debug for {char, str} in core::fmt
@diaphore
Copy link
Contributor Author

Looks like it. Thanks for your patience !

@alexcrichton
Copy link
Member

@bors: r+ aa89504

@bors
Copy link
Collaborator

bors commented Jul 28, 2015

⌛ Testing commit aa89504 with merge 4c371bb...

bors added a commit that referenced this pull request Jul 28, 2015
I had to modify some tests : since `wtf8buf_show` and `wtf8_show` were doing the exact same thing, I repurposed `wtf8_show` to `wtf8buf_show_str` which ensures `Wtf8Buf` `Debug`-formats the same as `str`.

`write_str_escaped` might also be shared amongst other `fmt` but I just left it there within `Wtf8::fmt` for review.
@bors bors merged commit aa89504 into rust-lang:master Jul 28, 2015
@diaphore diaphore deleted the pr_debug_osstr_escape branch July 28, 2015 12:19
@bluss
Copy link
Member

bluss commented Jul 28, 2015

Thanks @diaphore!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants