diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-17 06:37:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-17 06:37:38 +0100 |
| commit | 42114c9633711ee1af15f564a3614d318390f07c (patch) | |
| tree | 6126e378e84d8e1c416f903d8b9e8428567b4876 | |
| parent | 91481e3bcf4df9bee2a61c99894096864b9d7e83 (diff) | |
| parent | f68f0b3e118de3a0ce15524413ef1a04b164242c (diff) | |
| download | rust-42114c9633711ee1af15f564a3614d318390f07c.tar.gz rust-42114c9633711ee1af15f564a3614d318390f07c.zip | |
Rollup merge of #137101 - GrigorenkoPV:str-inherent-lint, r=Urgau
`invalid_from_utf8[_unchecked]`: also lint inherent methods Addressing https://github.com/rust-lang/rust/issues/131114#issuecomment-2646663535 Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
| -rw-r--r-- | clippy_lints/src/strings.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 6164a6191db..4a5f143a2d3 100644 --- a/clippy_lints/src/strings.rs +++ b/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 |
