1
Fork 0

invalid_from_utf8[_unchecked]: also lint inherent methods

This commit is contained in:
Pavel Grigorenko 2025-02-16 00:40:25 +03:00
parent 4229b80f50
commit f53d0f502d
6 changed files with 269 additions and 43 deletions

View file

@ -238,6 +238,7 @@ impl str {
/// assert_eq!("💖", sparkle_heart);
/// ```
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[rustc_diagnostic_item = "str_inherent_from_utf8"]
pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
converts::from_utf8(v)
}
@ -274,6 +275,7 @@ impl str {
/// errors that can be returned.
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")]
#[rustc_diagnostic_item = "str_inherent_from_utf8_mut"]
pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
converts::from_utf8_mut(v)
}
@ -306,6 +308,7 @@ impl str {
#[inline]
#[must_use]
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[rustc_diagnostic_item = "str_inherent_from_utf8_unchecked"]
pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
// SAFETY: converts::from_utf8_unchecked has the same safety requirements as this function.
unsafe { converts::from_utf8_unchecked(v) }
@ -331,6 +334,7 @@ impl str {
#[inline]
#[must_use]
#[unstable(feature = "inherent_str_constructors", issue = "131114")]
#[rustc_diagnostic_item = "str_inherent_from_utf8_unchecked_mut"]
pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {
// SAFETY: converts::from_utf8_unchecked_mut has the same safety requirements as this function.
unsafe { converts::from_utf8_unchecked_mut(v) }