mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Add 'must_use' attribute to 'char::len_utf8' and 'char::len_utf16';
This commit is contained in:
parent
1b5aa96d60
commit
b466fa6db8
@ -606,6 +606,7 @@ impl char {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_stable(feature = "const_char_len_utf", since = "1.52.0")]
|
#[rustc_const_stable(feature = "const_char_len_utf", since = "1.52.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
pub const fn len_utf8(self) -> usize {
|
pub const fn len_utf8(self) -> usize {
|
||||||
len_utf8(self as u32)
|
len_utf8(self as u32)
|
||||||
}
|
}
|
||||||
@ -637,6 +638,7 @@ impl char {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_stable(feature = "const_char_len_utf", since = "1.52.0")]
|
#[rustc_const_stable(feature = "const_char_len_utf", since = "1.52.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
pub const fn len_utf16(self) -> usize {
|
pub const fn len_utf16(self) -> usize {
|
||||||
len_utf16(self as u32)
|
len_utf16(self as u32)
|
||||||
}
|
}
|
||||||
@ -1738,6 +1740,7 @@ impl EscapeDebugExtArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
const fn len_utf8(code: u32) -> usize {
|
const fn len_utf8(code: u32) -> usize {
|
||||||
match code {
|
match code {
|
||||||
..MAX_ONE_B => 1,
|
..MAX_ONE_B => 1,
|
||||||
@ -1748,6 +1751,7 @@ const fn len_utf8(code: u32) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
const fn len_utf16(code: u32) -> usize {
|
const fn len_utf16(code: u32) -> usize {
|
||||||
if (code & 0xFFFF) == code { 1 } else { 2 }
|
if (code & 0xFFFF) == code { 1 } else { 2 }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user