diff options
| author | bors <bors@rust-lang.org> | 2017-12-18 02:54:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-18 02:54:11 +0000 |
| commit | a3a7203e2c9ed30a501da86f3fa1f9efe707ac94 (patch) | |
| tree | 862a6ca6053469cdac26ec03a14c02076945fd5a /src/libstd/sys | |
| parent | dc39c31699a83313edf2ac096d0bf3cef871b705 (diff) | |
| parent | 8fac7d95bc2429ff2156bf1afcf8972f92cd6afd (diff) | |
| download | rust-a3a7203e2c9ed30a501da86f3fa1f9efe707ac94.tar.gz rust-a3a7203e2c9ed30a501da86f3fa1f9efe707ac94.zip | |
Auto merge of #46798 - Diggsey:debug-osstr, r=dtolnay
Add lossless debug implementation for unix OsStrs
Fixes #22766
Invalid utf8 byte sequences are replaced with `\xFF` style escape codes, while valid utf8 goes through the normal `Debug` implementation.
This is necessarily different from the windows Debug implementation, which uses `\u{xxxx}` style escape sequences for unpaired surrogates, but both implementations are consistent in that they are both lossless, and display invalid sequences in the way most similar to existing language syntax.
r? @dtolnay
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/redox/os_str.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os_str.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/wasm/os_str.rs | 3 |
3 files changed, 6 insertions, 3 deletions
diff --git a/src/libstd/sys/redox/os_str.rs b/src/libstd/sys/redox/os_str.rs index 5c40d42fa0a..655bfdb9167 100644 --- a/src/libstd/sys/redox/os_str.rs +++ b/src/libstd/sys/redox/os_str.rs @@ -18,6 +18,7 @@ use mem; use rc::Rc; use sync::Arc; use sys_common::{AsInner, IntoInner}; +use sys_common::bytestring::debug_fmt_bytestring; use std_unicode::lossy::Utf8Lossy; #[derive(Clone, Hash)] @@ -31,7 +32,7 @@ pub struct Slice { impl fmt::Debug for Slice { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&Utf8Lossy::from_bytes(&self.inner), formatter) + debug_fmt_bytestring(&self.inner, formatter) } } diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs index a27e76a0e3b..e0349387998 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -18,6 +18,7 @@ use mem; use rc::Rc; use sync::Arc; use sys_common::{AsInner, IntoInner}; +use sys_common::bytestring::debug_fmt_bytestring; use std_unicode::lossy::Utf8Lossy; #[derive(Clone, Hash)] @@ -31,7 +32,7 @@ pub struct Slice { impl fmt::Debug for Slice { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&Utf8Lossy::from_bytes(&self.inner), formatter) + debug_fmt_bytestring(&self.inner, formatter) } } diff --git a/src/libstd/sys/wasm/os_str.rs b/src/libstd/sys/wasm/os_str.rs index 0e64b5bc6b8..543c22ebe18 100644 --- a/src/libstd/sys/wasm/os_str.rs +++ b/src/libstd/sys/wasm/os_str.rs @@ -18,6 +18,7 @@ use mem; use rc::Rc; use sync::Arc; use sys_common::{AsInner, IntoInner}; +use sys_common::bytestring::debug_fmt_bytestring; use std_unicode::lossy::Utf8Lossy; #[derive(Clone, Hash)] @@ -31,7 +32,7 @@ pub struct Slice { impl fmt::Debug for Slice { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&Utf8Lossy::from_bytes(&self.inner), formatter) + debug_fmt_bytestring(&self.inner, formatter) } } |
