Deprecate the AsciiExt trait in favor of inherent methods

The trait and some of its methods are stable and will remain.
Some of the newer methods are unstable and can be removed later.

Fixes https://github.com/rust-lang/rust/issues/39658
This commit is contained in:
Simon Sapin 2018-03-17 12:15:24 +01:00
parent cc34ca1c97
commit c09b9f9372
5 changed files with 24 additions and 16 deletions

View File

@ -9,7 +9,6 @@
// except according to those terms. // except according to those terms.
use core::char::from_u32; use core::char::from_u32;
use std::ascii::AsciiExt;
#[test] #[test]
fn test_is_ascii() { fn test_is_ascii() {
@ -143,8 +142,6 @@ macro_rules! assert_all {
stringify!($what), b); stringify!($what), b);
} }
} }
assert!($str.$what());
assert!($str.as_bytes().$what());
)+ )+
}}; }};
($what:ident, $($str:tt),+,) => (assert_all!($what,$($str),+)) ($what:ident, $($str:tt),+,) => (assert_all!($what,$($str),+))

View File

@ -52,6 +52,7 @@ pub use core::ascii::{EscapeDefault, escape_default};
/// ///
/// [combining character]: https://en.wikipedia.org/wiki/Combining_character /// [combining character]: https://en.wikipedia.org/wiki/Combining_character
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
pub trait AsciiExt { pub trait AsciiExt {
/// Container type for copied ASCII characters. /// Container type for copied ASCII characters.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -84,6 +85,7 @@ pub trait AsciiExt {
/// [`make_ascii_uppercase`]: #tymethod.make_ascii_uppercase /// [`make_ascii_uppercase`]: #tymethod.make_ascii_uppercase
/// [`str::to_uppercase`]: ../primitive.str.html#method.to_uppercase /// [`str::to_uppercase`]: ../primitive.str.html#method.to_uppercase
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
fn to_ascii_uppercase(&self) -> Self::Owned; fn to_ascii_uppercase(&self) -> Self::Owned;
/// Makes a copy of the value in its ASCII lower case equivalent. /// Makes a copy of the value in its ASCII lower case equivalent.
@ -104,6 +106,7 @@ pub trait AsciiExt {
/// [`make_ascii_lowercase`]: #tymethod.make_ascii_lowercase /// [`make_ascii_lowercase`]: #tymethod.make_ascii_lowercase
/// [`str::to_lowercase`]: ../primitive.str.html#method.to_lowercase /// [`str::to_lowercase`]: ../primitive.str.html#method.to_lowercase
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
fn to_ascii_lowercase(&self) -> Self::Owned; fn to_ascii_lowercase(&self) -> Self::Owned;
/// Checks that two values are an ASCII case-insensitive match. /// Checks that two values are an ASCII case-insensitive match.
@ -162,6 +165,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_alphabetic(&self) -> bool { unimplemented!(); } fn is_ascii_alphabetic(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII uppercase character: /// Checks if the value is an ASCII uppercase character:
@ -174,6 +178,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_uppercase(&self) -> bool { unimplemented!(); } fn is_ascii_uppercase(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII lowercase character: /// Checks if the value is an ASCII lowercase character:
@ -186,6 +191,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_lowercase(&self) -> bool { unimplemented!(); } fn is_ascii_lowercase(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII alphanumeric character: /// Checks if the value is an ASCII alphanumeric character:
@ -199,6 +205,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_alphanumeric(&self) -> bool { unimplemented!(); } fn is_ascii_alphanumeric(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII decimal digit: /// Checks if the value is an ASCII decimal digit:
@ -211,6 +218,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_digit(&self) -> bool { unimplemented!(); } fn is_ascii_digit(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII hexadecimal digit: /// Checks if the value is an ASCII hexadecimal digit:
@ -224,6 +232,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_hexdigit(&self) -> bool { unimplemented!(); } fn is_ascii_hexdigit(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII punctuation character: /// Checks if the value is an ASCII punctuation character:
@ -241,6 +250,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_punctuation(&self) -> bool { unimplemented!(); } fn is_ascii_punctuation(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII graphic character: /// Checks if the value is an ASCII graphic character:
@ -253,6 +263,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_graphic(&self) -> bool { unimplemented!(); } fn is_ascii_graphic(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII whitespace character: /// Checks if the value is an ASCII whitespace character:
@ -282,6 +293,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_whitespace(&self) -> bool { unimplemented!(); } fn is_ascii_whitespace(&self) -> bool { unimplemented!(); }
/// Checks if the value is an ASCII control character: /// Checks if the value is an ASCII control character:
@ -294,6 +306,7 @@ pub trait AsciiExt {
/// This method will be deprecated in favor of the identically-named /// This method will be deprecated in favor of the identically-named
/// inherent methods on `u8`, `char`, `[u8]` and `str`. /// inherent methods on `u8`, `char`, `[u8]` and `str`.
#[unstable(feature = "ascii_ctype", issue = "39658")] #[unstable(feature = "ascii_ctype", issue = "39658")]
#[rustc_deprecated(since = "1.26.0", reason = "use inherent methods instead")]
fn is_ascii_control(&self) -> bool { unimplemented!(); } fn is_ascii_control(&self) -> bool { unimplemented!(); }
} }
@ -354,6 +367,7 @@ macro_rules! delegating_ascii_ctype_methods {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl AsciiExt for u8 { impl AsciiExt for u8 {
type Owned = u8; type Owned = u8;
@ -362,6 +376,7 @@ impl AsciiExt for u8 {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl AsciiExt for char { impl AsciiExt for char {
type Owned = char; type Owned = char;
@ -370,6 +385,7 @@ impl AsciiExt for char {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl AsciiExt for [u8] { impl AsciiExt for [u8] {
type Owned = Vec<u8>; type Owned = Vec<u8>;
@ -427,6 +443,7 @@ impl AsciiExt for [u8] {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
impl AsciiExt for str { impl AsciiExt for str {
type Owned = String; type Owned = String;

View File

@ -10,7 +10,6 @@
#![unstable(feature = "process_internals", issue = "0")] #![unstable(feature = "process_internals", issue = "0")]
use ascii::AsciiExt;
use collections::BTreeMap; use collections::BTreeMap;
use env::split_paths; use env::split_paths;
use env; use env;

View File

@ -27,7 +27,6 @@
use core::str::next_code_point; use core::str::next_code_point;
use ascii::*;
use borrow::Cow; use borrow::Cow;
use char; use char;
use fmt; use fmt;
@ -871,24 +870,22 @@ impl Hash for Wtf8 {
} }
} }
impl AsciiExt for Wtf8 { impl Wtf8 {
type Owned = Wtf8Buf; pub fn is_ascii(&self) -> bool {
fn is_ascii(&self) -> bool {
self.bytes.is_ascii() self.bytes.is_ascii()
} }
fn to_ascii_uppercase(&self) -> Wtf8Buf { pub fn to_ascii_uppercase(&self) -> Wtf8Buf {
Wtf8Buf { bytes: self.bytes.to_ascii_uppercase() } Wtf8Buf { bytes: self.bytes.to_ascii_uppercase() }
} }
fn to_ascii_lowercase(&self) -> Wtf8Buf { pub fn to_ascii_lowercase(&self) -> Wtf8Buf {
Wtf8Buf { bytes: self.bytes.to_ascii_lowercase() } Wtf8Buf { bytes: self.bytes.to_ascii_lowercase() }
} }
fn eq_ignore_ascii_case(&self, other: &Wtf8) -> bool { pub fn eq_ignore_ascii_case(&self, other: &Wtf8) -> bool {
self.bytes.eq_ignore_ascii_case(&other.bytes) self.bytes.eq_ignore_ascii_case(&other.bytes)
} }
fn make_ascii_uppercase(&mut self) { self.bytes.make_ascii_uppercase() } pub fn make_ascii_uppercase(&mut self) { self.bytes.make_ascii_uppercase() }
fn make_ascii_lowercase(&mut self) { self.bytes.make_ascii_lowercase() } pub fn make_ascii_lowercase(&mut self) { self.bytes.make_ascii_lowercase() }
} }
#[cfg(test)] #[cfg(test)]

View File

@ -10,8 +10,6 @@
// pretty-expanded FIXME #23616 // pretty-expanded FIXME #23616
use std::ascii::AsciiExt;
static NAME: &'static str = "hello world"; static NAME: &'static str = "hello world";
fn main() { fn main() {