From f6d4720f26c92e9905c98b4ee2db832927e30a8a Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sat, 8 Feb 2020 21:27:13 -0800 Subject: [PATCH 1/2] Make `u8::is_ascii` a stable `const fn` `char::is_ascii` is already a stable `const fn`, so there is no reason for `u8::is_ascii` to be unstable. --- src/libcore/num/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index ed37b48b3e855..81ef99e5b1c2e 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4300,8 +4300,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 } From bf732a11ecc319e0c0a840196bde1b5daccbdc85 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sat, 8 Feb 2020 21:36:56 -0800 Subject: [PATCH 2/2] Test `u8::is_ascii` alongside `char::is_ascii` --- src/test/ui/consts/{std/char.rs => is_ascii.rs} | 6 ++++++ 1 file changed, 6 insertions(+) rename src/test/ui/consts/{std/char.rs => is_ascii.rs} (54%) diff --git a/src/test/ui/consts/std/char.rs b/src/test/ui/consts/is_ascii.rs similarity index 54% rename from src/test/ui/consts/std/char.rs rename to src/test/ui/consts/is_ascii.rs index fe79059a2e497..d8424549f93e6 100644 --- a/src/test/ui/consts/std/char.rs +++ b/src/test/ui/consts/is_ascii.rs @@ -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); }