From 5a1d11a733b856cfaedd82f1c1ff50b87541692d Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Sun, 1 Oct 2017 21:13:49 +0200 Subject: Copy `AsciiExt` methods to `[u8]` directly This is done in order to deprecate AsciiExt eventually. Note that this commit contains a bunch of `cfg(stage0)` statements. This is due to a new compiler feature I am using: the `slice_u8` lang item. Once this lang item is available in the stage0 compiler, all those cfg flags (and more) can be removed. --- src/liballoc/slice.rs | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 0c5fec2cf74..8268528acbd 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -1533,6 +1533,215 @@ impl [T] { } } +// TODO(LukasKalbertodt): the `not(stage0)` constraint can be removed in the +// future once the stage0 compiler is new enough to know about the `slice_u8` +// lang item. +#[lang = "slice_u8"] +#[cfg(all(not(stage0), not(test)))] +impl [u8] { + /// Checks if all bytes in this slice are within the ASCII range. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii(&self) -> bool { + self.iter().all(|b| b.is_ascii()) + } + + /// Returns a vector containing a copy of this slice where each byte + /// is mapped to its ASCII upper case equivalent. + /// + /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', + /// but non-ASCII letters are unchanged. + /// + /// To uppercase the value in-place, use [`make_ascii_uppercase`]. + /// + /// [`make_ascii_uppercase`]: #method.make_ascii_uppercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn to_ascii_uppercase(&self) -> Vec { + let mut me = self.to_vec(); + me.make_ascii_uppercase(); + me + } + + /// Returns a vector containing a copy of this slice where each byte + /// is mapped to its ASCII lower case equivalent. + /// + /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', + /// but non-ASCII letters are unchanged. + /// + /// To lowercase the value in-place, use [`make_ascii_lowercase`]. + /// + /// [`make_ascii_lowercase`]: #method.make_ascii_lowercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn to_ascii_lowercase(&self) -> Vec { + let mut me = self.to_vec(); + me.make_ascii_lowercase(); + me + } + + /// Checks that two slices are an ASCII case-insensitive match. + /// + /// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`, + /// but without allocating and copying temporaries. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool { + self.len() == other.len() && + self.iter().zip(other).all(|(a, b)| { + a.eq_ignore_ascii_case(b) + }) + } + + /// Converts this slice to its ASCII upper case equivalent in-place. + /// + /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', + /// but non-ASCII letters are unchanged. + /// + /// To return a new uppercased value without modifying the existing one, use + /// [`to_ascii_uppercase`]. + /// + /// [`to_ascii_uppercase`]: #method.to_ascii_uppercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn make_ascii_uppercase(&mut self) { + for byte in self { + byte.make_ascii_uppercase(); + } + } + + /// Converts this slice to its ASCII lower case equivalent in-place. + /// + /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', + /// but non-ASCII letters are unchanged. + /// + /// To return a new lowercased value without modifying the existing one, use + /// [`to_ascii_lowercase`]. + /// + /// [`to_ascii_lowercase`]: #method.to_ascii_lowercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn make_ascii_lowercase(&mut self) { + for byte in self { + byte.make_ascii_lowercase(); + } + } + + /// Checks if all bytes of this slice are ASCII alphabetic characters: + /// + /// - U+0041 'A' ... U+005A 'Z', or + /// - U+0061 'a' ... U+007A 'z'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_alphabetic(&self) -> bool { + self.iter().all(|b| b.is_ascii_alphabetic()) + } + + /// Checks if all bytes of this slice are ASCII uppercase characters: + /// U+0041 'A' ... U+005A 'Z'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_uppercase(&self) -> bool { + self.iter().all(|b| b.is_ascii_uppercase()) + } + + /// Checks if all bytes of this slice are ASCII lowercase characters: + /// U+0061 'a' ... U+007A 'z'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_lowercase(&self) -> bool { + self.iter().all(|b| b.is_ascii_lowercase()) + } + + /// Checks if all bytes of this slice are ASCII alphanumeric characters: + /// + /// - U+0041 'A' ... U+005A 'Z', or + /// - U+0061 'a' ... U+007A 'z', or + /// - U+0030 '0' ... U+0039 '9'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_alphanumeric(&self) -> bool { + self.iter().all(|b| b.is_ascii_alphanumeric()) + } + + /// Checks if all bytes of this slice are ASCII decimal digit: + /// U+0030 '0' ... U+0039 '9'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_digit(&self) -> bool { + self.iter().all(|b| b.is_ascii_digit()) + } + + /// Checks if all bytes of this slice are ASCII hexadecimal digits: + /// + /// - U+0030 '0' ... U+0039 '9', or + /// - U+0041 'A' ... U+0046 'F', or + /// - U+0061 'a' ... U+0066 'f'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_hexdigit(&self) -> bool { + self.iter().all(|b| b.is_ascii_hexdigit()) + } + + /// Checks if all bytes of this slice are ASCII punctuation characters: + /// + /// - U+0021 ... U+002F `! " # $ % & ' ( ) * + , - . /`, or + /// - U+003A ... U+0040 `: ; < = > ? @`, or + /// - U+005B ... U+0060 `[ \\ ] ^ _ \``, or + /// - U+007B ... U+007E `{ | } ~` + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_punctuation(&self) -> bool { + self.iter().all(|b| b.is_ascii_punctuation()) + } + + /// Checks if all bytes of this slice are ASCII graphic characters: + /// U+0021 '@' ... U+007E '~'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_graphic(&self) -> bool { + self.iter().all(|b| b.is_ascii_graphic()) + } + + /// Checks if all bytes of this slice are ASCII whitespace characters: + /// U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED, + /// U+000C FORM FEED, or U+000D CARRIAGE RETURN. + /// + /// Rust uses the WhatWG Infra Standard's [definition of ASCII + /// whitespace][infra-aw]. There are several other definitions in + /// wide use. For instance, [the POSIX locale][pct] includes + /// U+000B VERTICAL TAB as well as all the above characters, + /// but—from the very same specification—[the default rule for + /// "field splitting" in the Bourne shell][bfs] considers *only* + /// SPACE, HORIZONTAL TAB, and LINE FEED as whitespace. + /// + /// If you are writing a program that will process an existing + /// file format, check what that format's definition of whitespace is + /// before using this function. + /// + /// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace + /// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01 + /// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_whitespace(&self) -> bool { + self.iter().all(|b| b.is_ascii_whitespace()) + } + + /// Checks if all bytes of this slice are ASCII control characters: + /// + /// - U+0000 NUL ... U+001F UNIT SEPARATOR, or + /// - U+007F DELETE. + /// + /// Note that most ASCII whitespace characters are control + /// characters, but SPACE is not. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_control(&self) -> bool { + self.iter().all(|b| b.is_ascii_control()) + } +} + //////////////////////////////////////////////////////////////////////////////// // Extension traits for slices over specific kinds of data //////////////////////////////////////////////////////////////////////////////// -- cgit 1.4.1-3-g733a5 From 1916e3c4aad7b0e0de1cfd190819609f55520996 Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Sun, 1 Oct 2017 21:46:17 +0200 Subject: Copy `AsciiExt` methods to `str` directly This is done in order to deprecate AsciiExt eventually. Note that this commit contains a bunch of `cfg(stage0)` statements. This is due to a new compiler feature this commit depends on: the `slice_u8` lang item. Once this lang item is available in the stage0 compiler, all those cfg flags (and more) can be removed. --- src/liballoc/slice.rs | 2 +- src/liballoc/str.rs | 276 ++++++++++++++++++++++++++++++++++++++++++ src/libstd/ascii.rs | 16 ++- src/libsyntax/feature_gate.rs | 1 - 4 files changed, 290 insertions(+), 5 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 8268528acbd..7590003a681 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -1533,7 +1533,7 @@ impl [T] { } } -// TODO(LukasKalbertodt): the `not(stage0)` constraint can be removed in the +// FIXME(LukasKalbertodt): the `not(stage0)` constraint can be removed in the // future once the stage0 compiler is new enough to know about the `slice_u8` // lang item. #[lang = "slice_u8"] diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 895607ff8d4..2c257b8c736 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -2070,6 +2070,282 @@ impl str { s.extend((0..n).map(|_| self)); s } + + /// Checks if all characters in this string are within the ASCII range. + /// + /// # Examples + /// + /// ``` + /// let ascii = "hello!\n"; + /// let non_ascii = "Grüße, Jürgen ❤"; + /// + /// assert!(ascii.is_ascii()); + /// assert!(!non_ascii.is_ascii()); + /// ``` + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii(&self) -> bool { + // We can treat each byte as character here: all multibyte characters + // start with a byte that is not in the ascii range, so we will stop + // there already. + self.bytes().all(|b| b.is_ascii()) + } + + /// Returns a copy of this string where each character is mapped to its + /// ASCII upper case equivalent. + /// + /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', + /// but non-ASCII letters are unchanged. + /// + /// To uppercase the value in-place, use [`make_ascii_uppercase`]. + /// + /// To uppercase ASCII characters in addition to non-ASCII characters, use + /// [`to_uppercase`]. + /// + /// # Examples + /// + /// ``` + /// let s = "Grüße, Jürgen ❤"; + /// + /// assert_eq!("GRüßE, JüRGEN ❤", s.to_ascii_uppercase()); + /// ``` + /// + /// [`make_ascii_uppercase`]: #method.make_ascii_uppercase + /// [`to_uppercase`]: #method.to_uppercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + #[cfg(not(stage0))] + pub fn to_ascii_uppercase(&self) -> String { + let mut bytes = self.as_bytes().to_vec(); + bytes.make_ascii_uppercase(); + // make_ascii_uppercase() preserves the UTF-8 invariant. + unsafe { String::from_utf8_unchecked(bytes) } + } + + /// Returns a copy of this string where each character is mapped to its + /// ASCII lower case equivalent. + /// + /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', + /// but non-ASCII letters are unchanged. + /// + /// To lowercase the value in-place, use [`make_ascii_lowercase`]. + /// + /// To lowercase ASCII characters in addition to non-ASCII characters, use + /// [`to_lowercase`]. + /// + /// # Examples + /// + /// ``` + /// let s = "Grüße, Jürgen ❤"; + /// + /// assert_eq!("grüße, jürgen ❤", s.to_ascii_lowercase()); + /// ``` + /// + /// [`make_ascii_lowercase`]: #method.make_ascii_lowercase + /// [`to_lowercase`]: #method.to_lowercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + #[cfg(not(stage0))] + pub fn to_ascii_lowercase(&self) -> String { + let mut bytes = self.as_bytes().to_vec(); + bytes.make_ascii_lowercase(); + // make_ascii_lowercase() preserves the UTF-8 invariant. + unsafe { String::from_utf8_unchecked(bytes) } + } + + /// Checks that two strings are an ASCII case-insensitive match. + /// + /// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`, + /// but without allocating and copying temporaries. + /// + /// # Examples + /// + /// ``` + /// assert!("Ferris".eq_ignore_ascii_case("FERRIS")); + /// assert!("Ferrös".eq_ignore_ascii_case("FERRöS")); + /// assert!(!"Ferrös".eq_ignore_ascii_case("FERRÖS")); + /// ``` + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + #[cfg(not(stage0))] + pub fn eq_ignore_ascii_case(&self, other: &str) -> bool { + self.as_bytes().eq_ignore_ascii_case(other.as_bytes()) + } + + /// Converts this string to its ASCII upper case equivalent in-place. + /// + /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', + /// but non-ASCII letters are unchanged. + /// + /// To return a new uppercased value without modifying the existing one, use + /// [`to_ascii_uppercase`]. + /// + /// [`to_ascii_uppercase`]: #method.to_ascii_uppercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[cfg(not(stage0))] + pub fn make_ascii_uppercase(&mut self) { + let me = unsafe { self.as_bytes_mut() }; + me.make_ascii_uppercase() + } + + /// Converts this string to its ASCII lower case equivalent in-place. + /// + /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', + /// but non-ASCII letters are unchanged. + /// + /// To return a new lowercased value without modifying the existing one, use + /// [`to_ascii_lowercase`]. + /// + /// [`to_ascii_lowercase`]: #method.to_ascii_lowercase + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[cfg(not(stage0))] + pub fn make_ascii_lowercase(&mut self) { + let me = unsafe { self.as_bytes_mut() }; + me.make_ascii_lowercase() + } + + /// Checks if all characters of this string are ASCII alphabetic + /// characters: + /// + /// - U+0041 'A' ... U+005A 'Z', or + /// - U+0061 'a' ... U+007A 'z'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_alphabetic(&self) -> bool { + self.bytes().all(|b| b.is_ascii_alphabetic()) + } + + /// Checks if all characters of this string are ASCII uppercase characters: + /// U+0041 'A' ... U+005A 'Z'. + /// + /// # Example + /// + /// ``` + /// // Only ascii uppercase characters + /// assert!("HELLO".is_ascii_uppercase()); + /// + /// // While all characters are ascii, 'y' and 'e' are not uppercase + /// assert!(!"Bye".is_ascii_uppercase()); + /// + /// // While all characters are uppercase, 'Ü' is not ascii + /// assert!(!"TSCHÜSS".is_ascii_uppercase()); + /// ``` + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_uppercase(&self) -> bool { + self.bytes().all(|b| b.is_ascii_uppercase()) + } + + /// Checks if all characters of this string are ASCII lowercase characters: + /// U+0061 'a' ... U+007A 'z'. + /// + /// # Example + /// + /// ``` + /// // Only ascii uppercase characters + /// assert!("hello".is_ascii_lowercase()); + /// + /// // While all characters are ascii, 'B' is not lowercase + /// assert!(!"Bye".is_ascii_lowercase()); + /// + /// // While all characters are lowercase, 'Ü' is not ascii + /// assert!(!"tschüss".is_ascii_lowercase()); + /// ``` + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_lowercase(&self) -> bool { + self.bytes().all(|b| b.is_ascii_lowercase()) + } + + /// Checks if all characters of this string are ASCII alphanumeric + /// characters: + /// + /// - U+0041 'A' ... U+005A 'Z', or + /// - U+0061 'a' ... U+007A 'z', or + /// - U+0030 '0' ... U+0039 '9'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_alphanumeric(&self) -> bool { + self.bytes().all(|b| b.is_ascii_alphanumeric()) + } + + /// Checks if all characters of this string are ASCII decimal digit: + /// U+0030 '0' ... U+0039 '9'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_digit(&self) -> bool { + self.bytes().all(|b| b.is_ascii_digit()) + } + + /// Checks if all characters of this string are ASCII hexadecimal digits: + /// + /// - U+0030 '0' ... U+0039 '9', or + /// - U+0041 'A' ... U+0046 'F', or + /// - U+0061 'a' ... U+0066 'f'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_hexdigit(&self) -> bool { + self.bytes().all(|b| b.is_ascii_hexdigit()) + } + + /// Checks if all characters of this string are ASCII punctuation + /// characters: + /// + /// - U+0021 ... U+002F `! " # $ % & ' ( ) * + , - . /`, or + /// - U+003A ... U+0040 `: ; < = > ? @`, or + /// - U+005B ... U+0060 `[ \\ ] ^ _ \``, or + /// - U+007B ... U+007E `{ | } ~` + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_punctuation(&self) -> bool { + self.bytes().all(|b| b.is_ascii_punctuation()) + } + + /// Checks if all characters of this string are ASCII graphic characters: + /// U+0021 '@' ... U+007E '~'. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_graphic(&self) -> bool { + self.bytes().all(|b| b.is_ascii_graphic()) + } + + /// Checks if all characters of this string are ASCII whitespace characters: + /// U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED, + /// U+000C FORM FEED, or U+000D CARRIAGE RETURN. + /// + /// Rust uses the WhatWG Infra Standard's [definition of ASCII + /// whitespace][infra-aw]. There are several other definitions in + /// wide use. For instance, [the POSIX locale][pct] includes + /// U+000B VERTICAL TAB as well as all the above characters, + /// but—from the very same specification—[the default rule for + /// "field splitting" in the Bourne shell][bfs] considers *only* + /// SPACE, HORIZONTAL TAB, and LINE FEED as whitespace. + /// + /// If you are writing a program that will process an existing + /// file format, check what that format's definition of whitespace is + /// before using this function. + /// + /// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace + /// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01 + /// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_whitespace(&self) -> bool { + self.bytes().all(|b| b.is_ascii_whitespace()) + } + + /// Checks if all characters of this string are ASCII control characters: + /// + /// - U+0000 NUL ... U+001F UNIT SEPARATOR, or + /// - U+007F DELETE. + /// + /// Note that most ASCII whitespace characters are control + /// characters, but SPACE is not. + #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[inline] + pub fn is_ascii_control(&self) -> bool { + self.bytes().all(|b| b.is_ascii_control()) + } } /// Converts a boxed slice of bytes to a boxed string slice without checking diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 7a474c1f254..200264a2583 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -298,6 +298,10 @@ pub trait AsciiExt { fn is_ascii_control(&self) -> bool { unimplemented!(); } } +// FIXME(LukasKalbertodt): this impl block can be removed in the future. This is +// possible once the stage0 compiler is new enough to contain the inherent +// ascii methods for `[str]`. See FIXME comment further down. +#[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for str { type Owned = String; @@ -389,9 +393,9 @@ impl AsciiExt for str { } } -// TODO(LukasKalbertodt): this impl block can be removed in the future. This is +// FIXME(LukasKalbertodt): this impl block can be removed in the future. This is // possible once the stage0 compiler is new enough to contain the inherent -// ascii methods for `[u8]`. See TODO comment further down. +// ascii methods for `[u8]`. See FIXME comment further down. #[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for [u8] { @@ -546,12 +550,18 @@ macro_rules! impl_by_delegating { impl_by_delegating!(u8, u8); impl_by_delegating!(char, char); -// TODO(LukasKalbertodt): the macro invocation should replace the impl block +// FIXME(LukasKalbertodt): the macro invocation should replace the impl block // for `[u8]` above. But this is not possible until the stage0 compiler is new // enough to contain the inherent ascii methods for `[u8]`. #[cfg(not(stage0))] impl_by_delegating!([u8], Vec); +// FIXME(LukasKalbertodt): the macro invocation should replace the impl block +// for `str` above. But this is not possible until the stage0 compiler is new +// enough to contain the inherent ascii methods for `str`. +#[cfg(not(stage0))] +impl_by_delegating!(str, String); + /// An iterator over the escaped version of a byte. /// /// This `struct` is created by the [`escape_default`] function. See its diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 30451ec757a..195aac5292f 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -35,7 +35,6 @@ use visit::{self, FnKind, Visitor}; use parse::ParseSess; use symbol::Symbol; -use std::ascii::AsciiExt; use std::env; macro_rules! set { -- cgit 1.4.1-3-g733a5 From da57580736c6d30fec6c4e4442bc5376ac81f245 Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Mon, 2 Oct 2017 09:50:36 +0200 Subject: Remove unused AsciiExt imports and fix tests related to ascii methods Many AsciiExt imports have become useless thanks to the inherent ascii methods added in the last commits. These were removed. In some places, I fully specified the ascii method being called to enforce usage of the AsciiExt trait. Note that some imports are not removed but tagged with a `#[cfg(stage0)]` attribute. This is necessary, because certain ascii methods are not yet available in stage0. All those imports will be removed later. Additionally, failing tests were fixed. The test suite should exit successfully now. --- src/liballoc/benches/str.rs | 3 --- src/liballoc/borrow.rs | 1 - src/liballoc/str.rs | 4 ---- src/liballoc/string.rs | 2 -- src/liballoc/tests/str.rs | 1 - src/liballoc/tests/vec.rs | 3 --- src/liballoc/vec.rs | 2 -- src/librustc/lint/mod.rs | 1 + src/librustdoc/clean/cfg.rs | 1 + src/librustdoc/html/render.rs | 1 + src/libstd/ascii.rs | 8 +++++--- src/test/ui/deref-suggestion.stderr | 4 ++-- 12 files changed, 10 insertions(+), 21 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/benches/str.rs b/src/liballoc/benches/str.rs index fc4063fae92..38c94d4d8b5 100644 --- a/src/liballoc/benches/str.rs +++ b/src/liballoc/benches/str.rs @@ -272,15 +272,12 @@ make_test!(match_indices_a_str, s, s.match_indices("a").count()); make_test!(split_a_str, s, s.split("a").count()); make_test!(trim_ascii_char, s, { - use std::ascii::AsciiExt; s.trim_matches(|c: char| c.is_ascii()) }); make_test!(trim_left_ascii_char, s, { - use std::ascii::AsciiExt; s.trim_left_matches(|c: char| c.is_ascii()) }); make_test!(trim_right_ascii_char, s, { - use std::ascii::AsciiExt; s.trim_right_matches(|c: char| c.is_ascii()) }); diff --git a/src/liballoc/borrow.rs b/src/liballoc/borrow.rs index a662e4b1f4f..e8aff099871 100644 --- a/src/liballoc/borrow.rs +++ b/src/liballoc/borrow.rs @@ -191,7 +191,6 @@ impl<'a, B: ?Sized> Cow<'a, B> /// # Examples /// /// ``` - /// use std::ascii::AsciiExt; /// use std::borrow::Cow; /// /// let mut cow = Cow::Borrowed("foo"); diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 2c257b8c736..b75ecb6ea51 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -390,8 +390,6 @@ impl str { /// # Examples /// /// ``` - /// use std::ascii::AsciiExt; - /// /// let mut v = String::from("hello"); /// // correct length /// assert!(v.get_mut(0..5).is_some()); @@ -617,8 +615,6 @@ impl str { /// Basic usage: /// /// ``` - /// use std::ascii::AsciiExt; - /// /// let mut s = "Per Martin-Löf".to_string(); /// { /// let (first, last) = s.split_at_mut(3); diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 6d0bb264df1..25fcc1ccdab 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -773,8 +773,6 @@ impl String { /// Basic usage: /// /// ``` - /// use std::ascii::AsciiExt; - /// /// let mut s = String::from("foobar"); /// let s_mut_str = s.as_mut_str(); /// diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index b3178064505..6b075e7ac0e 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -706,7 +706,6 @@ fn test_split_at() { #[test] fn test_split_at_mut() { - use std::ascii::AsciiExt; let mut s = "Hello World".to_string(); { let (a, b) = s.split_at_mut(5); diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 0e25da5bd30..9cfde5dcc73 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::ascii::AsciiExt; use std::borrow::Cow; use std::mem::size_of; use std::panic; @@ -966,5 +965,3 @@ fn drain_filter_complex() { assert_eq!(vec, vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19]); } } - - diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index cf34e195dea..5aca199cf40 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -853,8 +853,6 @@ impl Vec { /// # Examples /// /// ``` - /// use std::ascii::AsciiExt; - /// /// let mut vec = vec!["foo", "bar", "Bar", "baz", "bar"]; /// /// vec.dedup_by(|a, b| a.eq_ignore_ascii_case(b)); diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index bca4dad220f..d648099d74d 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -38,6 +38,7 @@ use hir::def_id::{CrateNum, LOCAL_CRATE}; use hir::intravisit::{self, FnKind}; use hir; use session::Session; +#[cfg(stage0)] use std::ascii::AsciiExt; use std::hash; use syntax::ast; diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index e3ce403f3c1..915383d8189 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -15,6 +15,7 @@ use std::mem; use std::fmt::{self, Write}; use std::ops; +#[cfg(stage0)] use std::ascii::AsciiExt; use syntax::symbol::Symbol; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index edd01a66075..228bd7a0330 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -34,6 +34,7 @@ //! both occur before the crate is rendered. pub use self::ExternalLocation::*; +#[cfg(stage0)] use std::ascii::AsciiExt; use std::cell::RefCell; use std::cmp::Ordering; diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 200264a2583..96d719c528c 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -38,8 +38,8 @@ use iter::FusedIterator; /// ``` /// use std::ascii::AsciiExt; /// -/// assert_eq!("café".to_ascii_uppercase(), "CAFÉ"); -/// assert_eq!("café".to_ascii_uppercase(), "CAFé"); +/// assert_eq!(AsciiExt::to_ascii_uppercase("café"), "CAFÉ"); +/// assert_eq!(AsciiExt::to_ascii_uppercase("café"), "CAFé"); /// ``` /// /// In the first example, the lowercased string is represented `"cafe\u{301}"` @@ -681,7 +681,9 @@ impl fmt::Debug for EscapeDefault { #[cfg(test)] mod tests { - use super::*; + //! Note that most of these tests are not testing `AsciiExt` methods, but + //! test inherent ascii methods of char, u8, str and [u8]. `AsciiExt` is + //! just using those methods, though. use char::from_u32; #[test] diff --git a/src/test/ui/deref-suggestion.stderr b/src/test/ui/deref-suggestion.stderr index 5ad9c19fa8c..3ed3297e05e 100644 --- a/src/test/ui/deref-suggestion.stderr +++ b/src/test/ui/deref-suggestion.stderr @@ -10,8 +10,8 @@ error[E0308]: mismatched types - .escape_debug() - .escape_default() - .escape_unicode() - - .to_lowercase() - - .to_uppercase() + - .to_ascii_lowercase() + - .to_ascii_uppercase() error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:23:10 -- cgit 1.4.1-3-g733a5 From 259c125267fb8334ae7f70f4e1d1c2e0d9a56d59 Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Tue, 3 Oct 2017 17:39:31 +0200 Subject: Mark several ascii methods as unstable again We don't want to stabilize them now already. The goal of this set of commits is just to add inherent methods to the four types. Stabilizing all of those methods can be done later. --- src/liballoc/lib.rs | 1 + src/liballoc/slice.rs | 20 ++++++++++---------- src/liballoc/str.rs | 24 ++++++++++++++---------- src/libcore/num/mod.rs | 40 ++++++++++++++++++++++++++++++---------- src/librustdoc/lib.rs | 1 + src/libstd/lib.rs | 1 + src/libstd_unicode/char.rs | 40 ++++++++++++++++++++++++++++++---------- src/libstd_unicode/lib.rs | 1 + 8 files changed, 88 insertions(+), 40 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index f654a6b5ba4..a40ed060604 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -83,6 +83,7 @@ #![cfg_attr(not(test), feature(generator_trait))] #![cfg_attr(test, feature(rand, test))] #![feature(allow_internal_unstable)] +#![feature(ascii_ctype)] #![feature(box_patterns)] #![feature(box_syntax)] #![feature(cfg_target_has_atomic)] diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 7590003a681..b41cb912fe7 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -1631,7 +1631,7 @@ impl [u8] { /// /// - U+0041 'A' ... U+005A 'Z', or /// - U+0061 'a' ... U+007A 'z'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphabetic(&self) -> bool { self.iter().all(|b| b.is_ascii_alphabetic()) @@ -1639,7 +1639,7 @@ impl [u8] { /// Checks if all bytes of this slice are ASCII uppercase characters: /// U+0041 'A' ... U+005A 'Z'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_uppercase(&self) -> bool { self.iter().all(|b| b.is_ascii_uppercase()) @@ -1647,7 +1647,7 @@ impl [u8] { /// Checks if all bytes of this slice are ASCII lowercase characters: /// U+0061 'a' ... U+007A 'z'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_lowercase(&self) -> bool { self.iter().all(|b| b.is_ascii_lowercase()) @@ -1658,7 +1658,7 @@ impl [u8] { /// - U+0041 'A' ... U+005A 'Z', or /// - U+0061 'a' ... U+007A 'z', or /// - U+0030 '0' ... U+0039 '9'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphanumeric(&self) -> bool { self.iter().all(|b| b.is_ascii_alphanumeric()) @@ -1666,7 +1666,7 @@ impl [u8] { /// Checks if all bytes of this slice are ASCII decimal digit: /// U+0030 '0' ... U+0039 '9'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_digit(&self) -> bool { self.iter().all(|b| b.is_ascii_digit()) @@ -1677,7 +1677,7 @@ impl [u8] { /// - U+0030 '0' ... U+0039 '9', or /// - U+0041 'A' ... U+0046 'F', or /// - U+0061 'a' ... U+0066 'f'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_hexdigit(&self) -> bool { self.iter().all(|b| b.is_ascii_hexdigit()) @@ -1689,7 +1689,7 @@ impl [u8] { /// - U+003A ... U+0040 `: ; < = > ? @`, or /// - U+005B ... U+0060 `[ \\ ] ^ _ \``, or /// - U+007B ... U+007E `{ | } ~` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_punctuation(&self) -> bool { self.iter().all(|b| b.is_ascii_punctuation()) @@ -1697,7 +1697,7 @@ impl [u8] { /// Checks if all bytes of this slice are ASCII graphic characters: /// U+0021 '@' ... U+007E '~'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_graphic(&self) -> bool { self.iter().all(|b| b.is_ascii_graphic()) @@ -1722,7 +1722,7 @@ impl [u8] { /// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace /// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01 /// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_whitespace(&self) -> bool { self.iter().all(|b| b.is_ascii_whitespace()) @@ -1735,7 +1735,7 @@ impl [u8] { /// /// Note that most ASCII whitespace characters are control /// characters, but SPACE is not. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_control(&self) -> bool { self.iter().all(|b| b.is_ascii_control()) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index b75ecb6ea51..5f0b4088fc0 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -2205,7 +2205,7 @@ impl str { /// /// - U+0041 'A' ... U+005A 'Z', or /// - U+0061 'a' ... U+007A 'z'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphabetic(&self) -> bool { self.bytes().all(|b| b.is_ascii_alphabetic()) @@ -2217,6 +2217,8 @@ impl str { /// # Example /// /// ``` + /// #![feature(ascii_ctype)] + /// /// // Only ascii uppercase characters /// assert!("HELLO".is_ascii_uppercase()); /// @@ -2226,7 +2228,7 @@ impl str { /// // While all characters are uppercase, 'Ü' is not ascii /// assert!(!"TSCHÜSS".is_ascii_uppercase()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_uppercase(&self) -> bool { self.bytes().all(|b| b.is_ascii_uppercase()) @@ -2238,6 +2240,8 @@ impl str { /// # Example /// /// ``` + /// #![feature(ascii_ctype)] + /// /// // Only ascii uppercase characters /// assert!("hello".is_ascii_lowercase()); /// @@ -2247,7 +2251,7 @@ impl str { /// // While all characters are lowercase, 'Ü' is not ascii /// assert!(!"tschüss".is_ascii_lowercase()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_lowercase(&self) -> bool { self.bytes().all(|b| b.is_ascii_lowercase()) @@ -2259,7 +2263,7 @@ impl str { /// - U+0041 'A' ... U+005A 'Z', or /// - U+0061 'a' ... U+007A 'z', or /// - U+0030 '0' ... U+0039 '9'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphanumeric(&self) -> bool { self.bytes().all(|b| b.is_ascii_alphanumeric()) @@ -2267,7 +2271,7 @@ impl str { /// Checks if all characters of this string are ASCII decimal digit: /// U+0030 '0' ... U+0039 '9'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_digit(&self) -> bool { self.bytes().all(|b| b.is_ascii_digit()) @@ -2278,7 +2282,7 @@ impl str { /// - U+0030 '0' ... U+0039 '9', or /// - U+0041 'A' ... U+0046 'F', or /// - U+0061 'a' ... U+0066 'f'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_hexdigit(&self) -> bool { self.bytes().all(|b| b.is_ascii_hexdigit()) @@ -2291,7 +2295,7 @@ impl str { /// - U+003A ... U+0040 `: ; < = > ? @`, or /// - U+005B ... U+0060 `[ \\ ] ^ _ \``, or /// - U+007B ... U+007E `{ | } ~` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_punctuation(&self) -> bool { self.bytes().all(|b| b.is_ascii_punctuation()) @@ -2299,7 +2303,7 @@ impl str { /// Checks if all characters of this string are ASCII graphic characters: /// U+0021 '@' ... U+007E '~'. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_graphic(&self) -> bool { self.bytes().all(|b| b.is_ascii_graphic()) @@ -2324,7 +2328,7 @@ impl str { /// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace /// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01 /// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_whitespace(&self) -> bool { self.bytes().all(|b| b.is_ascii_whitespace()) @@ -2337,7 +2341,7 @@ impl str { /// /// Note that most ASCII whitespace characters are control /// characters, but SPACE is not. - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_control(&self) -> bool { self.bytes().all(|b| b.is_ascii_control()) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 174fffcc51a..104e0cdb741 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2396,6 +2396,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2416,7 +2418,7 @@ impl u8 { /// assert!(!lf.is_ascii_alphabetic()); /// assert!(!esc.is_ascii_alphabetic()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphabetic(&self) -> bool { if *self >= 0x80 { return false; } @@ -2432,6 +2434,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2452,7 +2456,7 @@ impl u8 { /// assert!(!lf.is_ascii_uppercase()); /// assert!(!esc.is_ascii_uppercase()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_uppercase(&self) -> bool { if *self >= 0x80 { return false } @@ -2468,6 +2472,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2488,7 +2494,7 @@ impl u8 { /// assert!(!lf.is_ascii_lowercase()); /// assert!(!esc.is_ascii_lowercase()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_lowercase(&self) -> bool { if *self >= 0x80 { return false } @@ -2507,6 +2513,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2527,7 +2535,7 @@ impl u8 { /// assert!(!lf.is_ascii_alphanumeric()); /// assert!(!esc.is_ascii_alphanumeric()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphanumeric(&self) -> bool { if *self >= 0x80 { return false } @@ -2543,6 +2551,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2563,7 +2573,7 @@ impl u8 { /// assert!(!lf.is_ascii_digit()); /// assert!(!esc.is_ascii_digit()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_digit(&self) -> bool { if *self >= 0x80 { return false } @@ -2582,6 +2592,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2602,7 +2614,7 @@ impl u8 { /// assert!(!lf.is_ascii_hexdigit()); /// assert!(!esc.is_ascii_hexdigit()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_hexdigit(&self) -> bool { if *self >= 0x80 { return false } @@ -2622,6 +2634,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2642,7 +2656,7 @@ impl u8 { /// assert!(!lf.is_ascii_punctuation()); /// assert!(!esc.is_ascii_punctuation()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_punctuation(&self) -> bool { if *self >= 0x80 { return false } @@ -2658,6 +2672,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2678,7 +2694,7 @@ impl u8 { /// assert!(!lf.is_ascii_graphic()); /// assert!(!esc.is_ascii_graphic()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_graphic(&self) -> bool { if *self >= 0x80 { return false; } @@ -2711,6 +2727,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2731,7 +2749,7 @@ impl u8 { /// assert!(lf.is_ascii_whitespace()); /// assert!(!esc.is_ascii_whitespace()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_whitespace(&self) -> bool { if *self >= 0x80 { return false; } @@ -2749,6 +2767,8 @@ impl u8 { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = b'A'; /// let uppercase_g = b'G'; /// let a = b'a'; @@ -2769,7 +2789,7 @@ impl u8 { /// assert!(lf.is_ascii_control()); /// assert!(esc.is_ascii_control()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_control(&self) -> bool { if *self >= 0x80 { return false; } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 500d0931708..fcb25f7aef3 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -14,6 +14,7 @@ html_playground_url = "https://play.rust-lang.org/")] #![deny(warnings)] +#![feature(ascii_ctype)] #![feature(rustc_private)] #![feature(box_patterns)] #![feature(box_syntax)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 5cf1d225b90..429153dc58b 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -244,6 +244,7 @@ #![feature(allow_internal_unstable)] #![feature(align_offset)] #![feature(array_error_internals)] +#![feature(ascii_ctype)] #![feature(asm)] #![feature(attr_literals)] #![feature(box_syntax)] diff --git a/src/libstd_unicode/char.rs b/src/libstd_unicode/char.rs index a9f46f17790..c012bdcb6db 100644 --- a/src/libstd_unicode/char.rs +++ b/src/libstd_unicode/char.rs @@ -1084,6 +1084,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1104,7 +1106,7 @@ impl char { /// assert!(!lf.is_ascii_alphabetic()); /// assert!(!esc.is_ascii_alphabetic()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphabetic(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_alphabetic() @@ -1116,6 +1118,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1136,7 +1140,7 @@ impl char { /// assert!(!lf.is_ascii_uppercase()); /// assert!(!esc.is_ascii_uppercase()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_uppercase(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_uppercase() @@ -1148,6 +1152,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1168,7 +1174,7 @@ impl char { /// assert!(!lf.is_ascii_lowercase()); /// assert!(!esc.is_ascii_lowercase()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_lowercase(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_lowercase() @@ -1183,6 +1189,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1203,7 +1211,7 @@ impl char { /// assert!(!lf.is_ascii_alphanumeric()); /// assert!(!esc.is_ascii_alphanumeric()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_alphanumeric(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_alphanumeric() @@ -1215,6 +1223,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1235,7 +1245,7 @@ impl char { /// assert!(!lf.is_ascii_digit()); /// assert!(!esc.is_ascii_digit()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_digit(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_digit() @@ -1250,6 +1260,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1270,7 +1282,7 @@ impl char { /// assert!(!lf.is_ascii_hexdigit()); /// assert!(!esc.is_ascii_hexdigit()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_hexdigit(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_hexdigit() @@ -1286,6 +1298,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1306,7 +1320,7 @@ impl char { /// assert!(!lf.is_ascii_punctuation()); /// assert!(!esc.is_ascii_punctuation()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_punctuation(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_punctuation() @@ -1318,6 +1332,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1338,7 +1354,7 @@ impl char { /// assert!(!lf.is_ascii_graphic()); /// assert!(!esc.is_ascii_graphic()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_graphic(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_graphic() @@ -1367,6 +1383,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1387,7 +1405,7 @@ impl char { /// assert!(lf.is_ascii_whitespace()); /// assert!(!esc.is_ascii_whitespace()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_whitespace(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_whitespace() @@ -1401,6 +1419,8 @@ impl char { /// # Examples /// /// ``` + /// #![feature(ascii_ctype)] + /// /// let uppercase_a = 'A'; /// let uppercase_g = 'G'; /// let a = 'a'; @@ -1421,7 +1441,7 @@ impl char { /// assert!(lf.is_ascii_control()); /// assert!(esc.is_ascii_control()); /// ``` - #[stable(feature = "ascii_methods_on_intrinsics", since = "1.21.0")] + #[unstable(feature = "ascii_ctype", issue = "39658")] #[inline] pub fn is_ascii_control(&self) -> bool { self.is_ascii() && (*self as u8).is_ascii_control() diff --git a/src/libstd_unicode/lib.rs b/src/libstd_unicode/lib.rs index e5a114caed0..65058b6554a 100644 --- a/src/libstd_unicode/lib.rs +++ b/src/libstd_unicode/lib.rs @@ -30,6 +30,7 @@ #![deny(warnings)] #![no_std] +#![feature(ascii_ctype)] #![feature(core_char_ext)] #![feature(str_internals)] #![feature(decode_utf8)] -- cgit 1.4.1-3-g733a5