Rollup merge of #68984 - ecstatic-morse:const-u8-is-ascii, r=sfackler

Make `u8::is_ascii` a stable `const fn`

`char::is_ascii` was already stabilized as `const fn` in #55278, so there is no reason for `u8::is_ascii` to go through an unstable period.

cc @rust-lang/libs
This commit is contained in:
Dylan DPC 2020-02-22 18:42:59 +05:30 committed by GitHub
commit c261ff1a77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -4324,8 +4324,9 @@ impl u8 {
/// assert!(!non_ascii.is_ascii());
/// ```
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.43.0")]
#[inline]
pub fn is_ascii(&self) -> bool {
pub const fn is_ascii(&self) -> bool {
*self & 128 == 0
}

View File

@ -3,7 +3,13 @@
static X: bool = 'a'.is_ascii();
static Y: bool = 'ä'.is_ascii();
static BX: bool = b'a'.is_ascii();
static BY: bool = 192u8.is_ascii();
fn main() {
assert!(X);
assert!(!Y);
assert!(BX);
assert!(!BY);
}