Auto merge of #132500 - RalfJung:char-is-whitespace-const, r=jhpratt
make char::is_whitespace unstably const I am adding this to the existing https://github.com/rust-lang/rust/issues/132241 feature gate, since `is_digit` and `is_whitespace` seem similar enough that one can group them together.
This commit is contained in:
commit
cf2b370ad0
@ -320,7 +320,7 @@ pub const fn from_digit(num: u32, radix: u32) -> Option<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()
|
||||
@ -856,8 +856,9 @@ pub const fn is_uppercase(self) -> bool {
|
||||
/// ```
|
||||
#[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),
|
||||
|
@ -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,
|
||||
|
@ -65,7 +65,7 @@ pub fn emit_cascading_map(&mut self, ranges: &[Range<u32>]) -> bool {
|
||||
self.bytes_used += 256;
|
||||
|
||||
writeln!(&mut self.file, "#[inline]").unwrap();
|
||||
writeln!(&mut self.file, "pub fn lookup(c: char) -> bool {{").unwrap();
|
||||
writeln!(&mut self.file, "pub const fn lookup(c: char) -> bool {{").unwrap();
|
||||
writeln!(&mut self.file, " match c as u32 >> 8 {{").unwrap();
|
||||
for arm in arms {
|
||||
writeln!(&mut self.file, " {},", arm).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user