Skip to content

Commit

Permalink
Rollup merge of rust-lang#68984 - ecstatic-morse:const-u8-is-ascii, r…
Browse files Browse the repository at this point in the history
…=sfackler

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

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

cc @rust-lang/libs
  • Loading branch information
Dylan-DPC authored Feb 22, 2020
2 parents 03d2f5c + bf732a1 commit c261ff1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit c261ff1

Please sign in to comment.