Skip to content

Commit 6f56b6b

Browse files
committed
Debug print char 0 as '\0' rather than '\u{0}'
1 parent 8bcf1ee commit 6f56b6b

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

alloc/tests/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn test_format_macro_interface() {
6969
t!(format!("{:?}", "true"), "\"true\"");
7070
t!(format!("{:?}", "foo\nbar"), "\"foo\\nbar\"");
7171
t!(format!("{:?}", "foo\n\"bar\"\r\n\'baz\'\t\\qux\\"), r#""foo\n\"bar\"\r\n'baz'\t\\qux\\""#);
72-
t!(format!("{:?}", "foo\0bar\x01baz\u{7f}q\u{75}x"), r#""foo\u{0}bar\u{1}baz\u{7f}qux""#);
72+
t!(format!("{:?}", "foo\0bar\x01baz\u{7f}q\u{75}x"), r#""foo\0bar\u{1}baz\u{7f}qux""#);
7373
t!(format!("{:o}", 10_usize), "12");
7474
t!(format!("{:x}", 10_usize), "a");
7575
t!(format!("{:X}", 10_usize), "A");

alloc/tests/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ fn test_escape_debug() {
11161116
assert_eq!("abc".escape_debug().to_string(), "abc");
11171117
assert_eq!("a c".escape_debug().to_string(), "a c");
11181118
assert_eq!("éèê".escape_debug().to_string(), "éèê");
1119-
assert_eq!("\r\n\t".escape_debug().to_string(), "\\r\\n\\t");
1119+
assert_eq!("\0\r\n\t".escape_debug().to_string(), "\\0\\r\\n\\t");
11201120
assert_eq!("'\"\\".escape_debug().to_string(), "\\'\\\"\\\\");
11211121
assert_eq!("\u{7f}\u{ff}".escape_debug().to_string(), "\\u{7f}\u{ff}");
11221122
assert_eq!("\u{100}\u{ffff}".escape_debug().to_string(), "\u{100}\\u{ffff}");

core/src/char/methods.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ impl char {
421421
#[inline]
422422
pub(crate) fn escape_debug_ext(self, args: EscapeDebugExtArgs) -> EscapeDebug {
423423
let init_state = match self {
424+
'\0' => EscapeDefaultState::Backslash('0'),
424425
'\t' => EscapeDefaultState::Backslash('t'),
425426
'\r' => EscapeDefaultState::Backslash('r'),
426427
'\n' => EscapeDefaultState::Backslash('n'),

core/tests/char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn test_escape_debug() {
197197
assert_eq!(string('~'), "~");
198198
assert_eq!(string('é'), "é");
199199
assert_eq!(string('文'), "文");
200-
assert_eq!(string('\x00'), "\\u{0}");
200+
assert_eq!(string('\x00'), "\\0");
201201
assert_eq!(string('\x1f'), "\\u{1f}");
202202
assert_eq!(string('\x7f'), "\\u{7f}");
203203
assert_eq!(string('\u{80}'), "\\u{80}");

0 commit comments

Comments
 (0)