about summary refs log tree commit diff
path: root/src/tools/clippy
diff options
context:
space:
mode:
authorPavel Grigorenko <GrigorenkoPV@ya.ru>2025-02-16 01:18:29 +0300
committerPavel Grigorenko <GrigorenkoPV@ya.ru>2025-02-16 16:34:51 +0300
commit77571a5c8bd1a8958865de75b8ec8b1bc2b4b756 (patch)
tree30f4a0cd35147c94724a588d40689e18b19a5c52 /src/tools/clippy
parentf53d0f502dba3b378d8baef159b97e685ba40f33 (diff)
downloadrust-77571a5c8bd1a8958865de75b8ec8b1bc2b4b756.tar.gz
rust-77571a5c8bd1a8958865de75b8ec8b1bc2b4b756.zip
clippy: string_from_utf8_as_bytes: also detect inherent `from_utf8`
Diffstat (limited to 'src/tools/clippy')
-rw-r--r--src/tools/clippy/clippy_lints/src/strings.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/tools/clippy/clippy_lints/src/strings.rs b/src/tools/clippy/clippy_lints/src/strings.rs
index 6164a6191db..4a5f143a2d3 100644
--- a/src/tools/clippy/clippy_lints/src/strings.rs
+++ b/src/tools/clippy/clippy_lints/src/strings.rs
@@ -2,8 +2,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the
 use clippy_utils::source::{snippet, snippet_with_applicability};
 use clippy_utils::ty::is_type_lang_item;
 use clippy_utils::{
-    SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, is_path_diagnostic_item,
-    method_calls, peel_blocks,
+    SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, path_def_id,
+    peel_blocks,
 };
 use rustc_errors::Applicability;
 use rustc_hir::def_id::DefId;
@@ -253,8 +253,9 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
         use rustc_ast::LitKind;
 
         if let ExprKind::Call(fun, [bytes_arg]) = e.kind
-            // Find std::str::converts::from_utf8
-            && is_path_diagnostic_item(cx, fun, sym::str_from_utf8)
+            // Find `std::str::converts::from_utf8` or `std::primitive::str::from_utf8`
+            && let Some(sym::str_from_utf8 | sym::str_inherent_from_utf8) =
+                path_def_id(cx, fun).and_then(|id| cx.tcx.get_diagnostic_name(id))
 
             // Find string::as_bytes
             && let ExprKind::AddrOf(BorrowKind::Ref, _, args) = bytes_arg.kind