From 3d09b4a0d58200da84fe19cd3b0003d61e5b1791 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 27 Jul 2016 12:10:31 +0200 Subject: [PATCH] Rename `char::escape` to `char::escape_debug` and add tracking issue --- src/libcollections/lib.rs | 2 +- src/libcollections/str.rs | 6 ++--- src/libcollectionstest/str.rs | 22 ++++++++--------- src/libcore/char.rs | 24 +++++++++---------- src/libcore/fmt/mod.rs | 4 ++-- src/libcoretest/char.rs | 4 ++-- src/libcoretest/lib.rs | 3 ++- src/librustc_unicode/char.rs | 8 +++---- src/librustc_unicode/lib.rs | 2 +- src/libstd/lib.rs | 15 ++++++------ src/libstd/sys/common/wtf8.rs | 6 ++--- .../sync-send-iterators-in-libcore.rs | 2 +- 12 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 333219bc5e5..7fc6e54d69f 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -33,7 +33,7 @@ #![feature(allow_internal_unstable)] #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(char_escape)] +#![cfg_attr(not(test), feature(char_escape_debug))] #![feature(core_intrinsics)] #![feature(dropck_parametricity)] #![feature(fmt_internals)] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index a63ea9d3ec7..4c64019de09 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1697,12 +1697,12 @@ pub fn to_uppercase(&self) -> String { return s; } - /// Escapes each char in `s` with `char::escape`. + /// Escapes each char in `s` with `char::escape_debug`. #[unstable(feature = "str_escape", reason = "return type may change to be an iterator", issue = "27791")] - pub fn escape(&self) -> String { - self.chars().flat_map(|c| c.escape()).collect() + pub fn escape_debug(&self) -> String { + self.chars().flat_map(|c| c.escape_debug()).collect() } /// Escapes each char in `s` with `char::escape_default`. diff --git a/src/libcollectionstest/str.rs b/src/libcollectionstest/str.rs index 870f8a3a1ec..a61925cd3be 100644 --- a/src/libcollectionstest/str.rs +++ b/src/libcollectionstest/str.rs @@ -704,17 +704,17 @@ fn test_escape_unicode() { } #[test] -fn test_escape() { - assert_eq!("abc".escape_default(), "abc"); - assert_eq!("a c".escape_default(), "a c"); - assert_eq!("éèê".escape_default(), "éèê"); - assert_eq!("\r\n\t".escape_default(), "\\r\\n\\t"); - assert_eq!("'\"\\".escape_default(), "\\'\\\"\\\\"); - assert_eq!("\u{7f}\u{ff}".escape_default(), "\\u{7f}\u{ff}"); - assert_eq!("\u{100}\u{ffff}".escape_default(), "\u{100}\\u{ffff}"); - assert_eq!("\u{10000}\u{10ffff}".escape_default(), "\u{10000}\\u{10ffff}"); - assert_eq!("ab\u{200b}".escape_default(), "ab\\u{200b}"); - assert_eq!("\u{10d4ea}\r".escape_default(), "\\u{10d4ea}\\r"); +fn test_escape_debug() { + assert_eq!("abc".escape_debug(), "abc"); + assert_eq!("a c".escape_debug(), "a c"); + assert_eq!("éèê".escape_debug(), "éèê"); + assert_eq!("\r\n\t".escape_debug(), "\\r\\n\\t"); + assert_eq!("'\"\\".escape_debug(), "\\'\\\"\\\\"); + assert_eq!("\u{7f}\u{ff}".escape_debug(), "\\u{7f}\u{ff}"); + assert_eq!("\u{100}\u{ffff}".escape_debug(), "\u{100}\\u{ffff}"); + assert_eq!("\u{10000}\u{10ffff}".escape_debug(), "\u{10000}\\u{10ffff}"); + assert_eq!("ab\u{200b}".escape_debug(), "ab\\u{200b}"); + assert_eq!("\u{10d4ea}\r".escape_debug(), "\\u{10d4ea}\\r"); } #[test] diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 3e435b47110..a3440fe8aa6 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -264,8 +264,8 @@ pub trait CharExt { fn escape_unicode(self) -> EscapeUnicode; #[stable(feature = "core", since = "1.6.0")] fn escape_default(self) -> EscapeDefault; - #[unstable(feature = "char_escape", issue = "0")] - fn escape(self) -> Escape; + #[unstable(feature = "char_escape_debug", issue = "35068")] + fn escape_debug(self) -> EscapeDebug; #[stable(feature = "core", since = "1.6.0")] fn len_utf8(self) -> usize; #[stable(feature = "core", since = "1.6.0")] @@ -330,7 +330,7 @@ fn escape_default(self) -> EscapeDefault { } #[inline] - fn escape(self) -> Escape { + fn escape_debug(self) -> EscapeDebug { let init_state = match self { '\t' => EscapeDefaultState::Backslash('t'), '\r' => EscapeDefaultState::Backslash('r'), @@ -339,7 +339,7 @@ fn escape(self) -> Escape { c if is_printable(c) => EscapeDefaultState::Char(c), c => EscapeDefaultState::Unicode(c.escape_unicode()), }; - Escape(EscapeDefault { state: init_state }) + EscapeDebug(EscapeDefault { state: init_state }) } #[inline] @@ -618,24 +618,24 @@ fn len(&self) -> usize { /// An iterator that yields the literal escape code of a `char`. /// -/// This `struct` is created by the [`escape()`] method on [`char`]. See its +/// This `struct` is created by the [`escape_debug()`] method on [`char`]. See its /// documentation for more. /// -/// [`escape()`]: ../../std/primitive.char.html#method.escape +/// [`escape_debug()`]: ../../std/primitive.char.html#method.escape_debug /// [`char`]: ../../std/primitive.char.html -#[unstable(feature = "char_escape", issue = "0")] +#[unstable(feature = "char_escape_debug", issue = "35068")] #[derive(Clone, Debug)] -pub struct Escape(EscapeDefault); +pub struct EscapeDebug(EscapeDefault); -#[unstable(feature = "char_escape", issue = "0")] -impl Iterator for Escape { +#[unstable(feature = "char_escape_debug", issue = "35068")] +impl Iterator for EscapeDebug { type Item = char; fn next(&mut self) -> Option { self.0.next() } fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } } -#[unstable(feature = "char_escape", issue = "0")] -impl ExactSizeIterator for Escape { } +#[unstable(feature = "char_escape_debug", issue = "35068")] +impl ExactSizeIterator for EscapeDebug { } /// An iterator over `u8` entries represending the UTF-8 encoding of a `char` /// value. diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 3bcdce57af0..173c55e35d5 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1383,7 +1383,7 @@ fn fmt(&self, f: &mut Formatter) -> Result { f.write_char('"')?; let mut from = 0; for (i, c) in self.char_indices() { - let esc = c.escape(); + let esc = c.escape_debug(); // If char needs escaping, flush backlog so far and write, else skip if esc.len() != 1 { f.write_str(&self[from..i])?; @@ -1409,7 +1409,7 @@ fn fmt(&self, f: &mut Formatter) -> Result { impl Debug for char { fn fmt(&self, f: &mut Formatter) -> Result { f.write_char('\'')?; - for c in self.escape() { + for c in self.escape_debug() { f.write_char(c)? } f.write_char('\'') diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index ec757b0b5d3..4632419336d 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -124,9 +124,9 @@ fn test_is_digit() { } #[test] -fn test_escape() { +fn test_escape_debug() { fn string(c: char) -> String { - c.escape().collect() + c.escape_debug().collect() } let s = string('\n'); assert_eq!(s, "\\n"); diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 1ef2b58351f..ef0042808f9 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -14,6 +14,7 @@ #![feature(borrow_state)] #![feature(box_syntax)] #![feature(cell_extras)] +#![feature(char_escape_debug)] #![feature(const_fn)] #![feature(core_private_bignum)] #![feature(core_private_diy_float)] @@ -29,10 +30,10 @@ #![feature(slice_patterns)] #![feature(step_by)] #![feature(test)] +#![feature(try_from)] #![feature(unboxed_closures)] #![feature(unicode)] #![feature(unique)] -#![feature(try_from)] extern crate core; extern crate test; diff --git a/src/librustc_unicode/char.rs b/src/librustc_unicode/char.rs index 683d5289ab5..7e308684a25 100644 --- a/src/librustc_unicode/char.rs +++ b/src/librustc_unicode/char.rs @@ -36,7 +36,7 @@ #[stable(feature = "rust1", since = "1.0.0")] pub use core::char::{MAX, from_digit, from_u32, from_u32_unchecked}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::char::{EncodeUtf16, EncodeUtf8, Escape, EscapeDefault, EscapeUnicode}; +pub use core::char::{EncodeUtf16, EncodeUtf8, EscapeDebug, EscapeDefault, EscapeUnicode}; // unstable reexports #[unstable(feature = "decode_utf8", issue = "33906")] @@ -296,10 +296,10 @@ pub fn escape_unicode(self) -> EscapeUnicode { /// /// assert_eq!(quote, "\\n"); /// ``` - #[unstable(feature = "char_escape", issue = "0")] + #[unstable(feature = "char_escape_debug", issue = "35068")] #[inline] - pub fn escape(self) -> Escape { - C::escape(self) + pub fn escape_debug(self) -> EscapeDebug { + C::escape_debug(self) } /// Returns an iterator that yields the literal escape code of a `char`. diff --git a/src/librustc_unicode/lib.rs b/src/librustc_unicode/lib.rs index 8c91d3b6a92..3ae905eba27 100644 --- a/src/librustc_unicode/lib.rs +++ b/src/librustc_unicode/lib.rs @@ -32,7 +32,7 @@ #![cfg_attr(not(stage0), deny(warnings))] #![no_std] -#![feature(char_escape)] +#![feature(char_escape_debug)] #![feature(core_char_ext)] #![feature(decode_utf8)] #![feature(lang_items)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d05a5a09614..865d067cdb6 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -218,8 +218,9 @@ #![feature(associated_consts)] #![feature(borrow_state)] #![feature(box_syntax)] -#![feature(cfg_target_vendor)] #![feature(cfg_target_thread_local)] +#![feature(cfg_target_vendor)] +#![feature(char_escape_debug)] #![feature(char_internals)] #![feature(collections)] #![feature(collections_bound)] @@ -229,10 +230,10 @@ #![feature(dropck_parametricity)] #![feature(float_extras)] #![feature(float_from_str_radix)] -#![feature(fnbox)] #![feature(fn_traits)] -#![feature(heap_api)] +#![feature(fnbox)] #![feature(hashmap_hasher)] +#![feature(heap_api)] #![feature(inclusive_range)] #![feature(int_error_internals)] #![feature(into_cow)] @@ -242,6 +243,7 @@ #![feature(linkage)] #![feature(macro_reexport)] #![cfg_attr(test, feature(map_values_mut))] +#![feature(needs_panic_runtime)] #![feature(num_bits_bytes)] #![feature(old_wrapping)] #![feature(on_unimplemented)] @@ -249,10 +251,11 @@ #![feature(optin_builtin_traits)] #![feature(panic_unwind)] #![feature(placement_in_syntax)] +#![feature(question_mark)] #![feature(rand)] #![feature(raw)] -#![feature(repr_simd)] #![feature(reflect_marker)] +#![feature(repr_simd)] #![feature(rustc_attrs)] #![feature(shared)] #![feature(sip_hash_13)] @@ -266,6 +269,7 @@ #![feature(str_utf16)] #![feature(test, rustc_private)] #![feature(thread_local)] +#![feature(try_from)] #![feature(unboxed_closures)] #![feature(unicode)] #![feature(unique)] @@ -273,9 +277,6 @@ #![feature(unwind_attributes)] #![feature(vec_push_all)] #![feature(zero_one)] -#![feature(question_mark)] -#![feature(try_from)] -#![feature(needs_panic_runtime)] // Issue# 30592: Systematically use alloc_system during stage0 since jemalloc // might be unavailable or disabled diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 2c1a656290f..c0e6ec46b55 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -390,7 +390,7 @@ impl fmt::Debug for Wtf8 { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn write_str_escaped(f: &mut fmt::Formatter, s: &str) -> fmt::Result { use fmt::Write; - for c in s.chars().flat_map(|c| c.escape_default()) { + for c in s.chars().flat_map(|c| c.escape_debug()) { f.write_char(c)? } Ok(()) @@ -1064,9 +1064,9 @@ fn c(value: &u32) -> CodePoint { CodePoint::from_u32(*value).unwrap() } #[test] fn wtf8buf_show() { - let mut string = Wtf8Buf::from_str("a\té 💩\r"); + let mut string = Wtf8Buf::from_str("a\té \u{7f}💩\r"); string.push(CodePoint::from_u32(0xD800).unwrap()); - assert_eq!(format!("{:?}", string), r#""a\t\u{e9} \u{1f4a9}\r\u{D800}""#); + assert_eq!(format!("{:?}", string), "\"a\\té \\u{7f}\u{1f4a9}\\r\\u{D800}\""); } #[test] diff --git a/src/test/run-pass/sync-send-iterators-in-libcore.rs b/src/test/run-pass/sync-send-iterators-in-libcore.rs index 93178994815..d12bdf182fa 100644 --- a/src/test/run-pass/sync-send-iterators-in-libcore.rs +++ b/src/test/run-pass/sync-send-iterators-in-libcore.rs @@ -67,7 +67,7 @@ macro_rules! is_sync_send { fn main() { // for char.rs - all_sync_send!("Я", escape_default, escape_unicode); + all_sync_send!("Я", escape_debug, escape_default, escape_unicode); // for iter.rs all_sync_send_mutable_ref!([1], iter); -- 2.44.0