Skip to content

Commit 77571a5

Browse files
committed
clippy: string_from_utf8_as_bytes: also detect inherent from_utf8
1 parent f53d0f5 commit 77571a5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/tools/clippy/clippy_lints/src/strings.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the
22
use clippy_utils::source::{snippet, snippet_with_applicability};
33
use clippy_utils::ty::is_type_lang_item;
44
use clippy_utils::{
5-
SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, is_path_diagnostic_item,
6-
method_calls, peel_blocks,
5+
SpanlessEq, get_expr_use_or_unification_node, get_parent_expr, is_lint_allowed, method_calls, path_def_id,
6+
peel_blocks,
77
};
88
use rustc_errors::Applicability;
99
use rustc_hir::def_id::DefId;
@@ -253,8 +253,9 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
253253
use rustc_ast::LitKind;
254254

255255
if let ExprKind::Call(fun, [bytes_arg]) = e.kind
256-
// Find std::str::converts::from_utf8
257-
&& is_path_diagnostic_item(cx, fun, sym::str_from_utf8)
256+
// Find `std::str::converts::from_utf8` or `std::primitive::str::from_utf8`
257+
&& let Some(sym::str_from_utf8 | sym::str_inherent_from_utf8) =
258+
path_def_id(cx, fun).and_then(|id| cx.tcx.get_diagnostic_name(id))
258259

259260
// Find string::as_bytes
260261
&& let ExprKind::AddrOf(BorrowKind::Ref, _, args) = bytes_arg.kind

0 commit comments

Comments
 (0)