Skip to content

Commit

Permalink
Auto merge of rust-lang#132500 - RalfJung:char-is-whitespace-const, r…
Browse files Browse the repository at this point in the history
…=jhpratt

make char::is_whitespace unstably const

I am adding this to the existing rust-lang#132241 feature gate, since `is_digit` and `is_whitespace` seem similar enough that one can group them together.
  • Loading branch information
bors committed Nov 6, 2024
2 parents f4e9fe4 + 11dc6c3 commit 41b7e5f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl char {
/// '1'.is_digit(37);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_char_is_digit", issue = "132241")]
#[rustc_const_unstable(feature = "const_char_classify", issue = "132241")]
#[inline]
pub const fn is_digit(self, radix: u32) -> bool {
self.to_digit(radix).is_some()
Expand Down Expand Up @@ -856,8 +856,9 @@ impl char {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_char_classify", issue = "132241")]
#[inline]
pub fn is_whitespace(self) -> bool {
pub const fn is_whitespace(self) -> bool {
match self {
' ' | '\x09'..='\x0d' => true,
c => c > '\x7f' && unicode::White_Space(c),
Expand Down
2 changes: 1 addition & 1 deletion core/src/unicode/unicode_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ pub mod white_space {
0, 0, 0, 0, 0, 0, 0, 0, 0,
];
#[inline]
pub fn lookup(c: char) -> bool {
pub const fn lookup(c: char) -> bool {
match c as u32 >> 8 {
0 => WHITESPACE_MAP[c as usize & 0xff] & 1 != 0,
22 => c as u32 == 0x1680,
Expand Down

0 comments on commit 41b7e5f

Please sign in to comment.