about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/invalid_from_utf8.rs
diff options
context:
space:
mode:
authorPavel Grigorenko <GrigorenkoPV@ya.ru>2025-02-16 00:40:25 +0300
committerPavel Grigorenko <GrigorenkoPV@ya.ru>2025-02-16 16:34:51 +0300
commitf53d0f502dba3b378d8baef159b97e685ba40f33 (patch)
tree3bdd1cb0596dc0872e9aa0a8d9442971c53a24e1 /compiler/rustc_lint/src/invalid_from_utf8.rs
parent4229b80f506d5c1e6267f27e69f10fa3bd3c8f9e (diff)
downloadrust-f53d0f502dba3b378d8baef159b97e685ba40f33.tar.gz
rust-f53d0f502dba3b378d8baef159b97e685ba40f33.zip
invalid_from_utf8[_unchecked]: also lint inherent methods
Diffstat (limited to 'compiler/rustc_lint/src/invalid_from_utf8.rs')
-rw-r--r--compiler/rustc_lint/src/invalid_from_utf8.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/invalid_from_utf8.rs b/compiler/rustc_lint/src/invalid_from_utf8.rs
index 0081374922e..11eb079ddc0 100644
--- a/compiler/rustc_lint/src/invalid_from_utf8.rs
+++ b/compiler/rustc_lint/src/invalid_from_utf8.rs
@@ -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");