Skip to content

Commit d7aca22

Browse files
committed
Auto merge of #95345 - dtolnay:escape0, r=Dylan-DPC
Debug print char 0 as '\0' rather than '\u{0}' ```rust println!("{:?}", "foo\0"); ``` - **Before:** `"foo\u{0}"` - **After:** `"foo\0"` ```rust println!("{:?}", '\0'); ``` - **Before:** `'\u{0}'` - **After:** `'\0'` `'\0'` will be more recognizable to everyone than `'\u{0}'` because it's how we talk about character 0 in all of our docs and example code, such as https://doc.rust-lang.org/std/ffi/index.html, https://doc.rust-lang.org/std/ffi/struct.CStr.html, https://doc.rust-lang.org/std/ffi/struct.CString.html.
2 parents 100f12d + 2ac9efb commit d7aca22

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

library/alloc/tests/fmt.rs

+1-1
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");

library/alloc/tests/str.rs

+1-1
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}");

library/core/src/char/methods.rs

+1
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'),

library/core/tests/char.rs

+1-1
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}");

src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ LL ~ match $s { $($t)+ => {}
5050
LL ~ '\u{10fffe}'..='\u{10ffff}' => todo!() }
5151
|
5252

53-
error[E0004]: non-exhaustive patterns: `'\u{0}'` not covered
53+
error[E0004]: non-exhaustive patterns: `'\0'` not covered
5454
--> $DIR/half-open-range-pats-exhaustive-fail.rs:28:8
5555
|
5656
LL | m!('a', ALMOST_MIN..);
57-
| ^^^ pattern `'\u{0}'` not covered
57+
| ^^^ pattern `'\0'` not covered
5858
|
5959
= note: the matched value is of type `char`
6060
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
6161
|
6262
LL ~ match $s { $($t)+ => {}
63-
LL ~ '\u{0}' => todo!() }
63+
LL ~ '\0' => todo!() }
6464
|
6565

6666
error[E0004]: non-exhaustive patterns: `'\u{10ffff}'` not covered

0 commit comments

Comments
 (0)