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

@ -70,12 +70,20 @@ impl<'tcx> LateLintPass<'tcx> for InvalidFromUtf8 {
sym::str_from_utf8_mut,
sym::str_from_utf8_unchecked,
sym::str_from_utf8_unchecked_mut,
sym::str_inherent_from_utf8,
sym::str_inherent_from_utf8_mut,
sym::str_inherent_from_utf8_unchecked,
sym::str_inherent_from_utf8_unchecked_mut,
]
.contains(&diag_item)
{
let lint = |label, utf8_error: Utf8Error| {
let method = diag_item.as_str().strip_prefix("str_").unwrap();
let method = format!("std::str::{method}");
let method = if let Some(method) = method.strip_prefix("inherent_") {
format!("str::{method}")
} else {
format!("std::str::{method}")
};
let valid_up_to = utf8_error.valid_up_to();
let is_unchecked_variant = diag_item.as_str().contains("unchecked");