Skip to content

Commit c261ff1

Browse files
authored
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
2 parents 03d2f5c + bf732a1 commit c261ff1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/libcore/num/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4324,8 +4324,9 @@ impl u8 {
43244324
/// assert!(!non_ascii.is_ascii());
43254325
/// ```
43264326
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
4327+
#[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.43.0")]
43274328
#[inline]
4328-
pub fn is_ascii(&self) -> bool {
4329+
pub const fn is_ascii(&self) -> bool {
43294330
*self & 128 == 0
43304331
}
43314332

src/test/ui/consts/std/char.rs src/test/ui/consts/is_ascii.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
static X: bool = 'a'.is_ascii();
44
static Y: bool = 'ä'.is_ascii();
55

6+
static BX: bool = b'a'.is_ascii();
7+
static BY: bool = 192u8.is_ascii();
8+
69
fn main() {
710
assert!(X);
811
assert!(!Y);
12+
13+
assert!(BX);
14+
assert!(!BY);
915
}

0 commit comments

Comments
 (0)