about summary refs log tree commit diff
diff options
context:
space:
mode:
authorwowinter13 <vla-dy@yandex.ru>2025-01-16 01:42:41 +0100
committerwowinter13 <vla-dy@yandex.ru>2025-01-25 18:43:07 +0100
commit5855e0a2f1df8a939342b16c0e7337cd393527d7 (patch)
treefd88140fe9e8da6a5670edea12ffb6c85f4afcd9
parent4fef1b46bea9a56d4170b1321787ee20e7406366 (diff)
downloadrust-5855e0a2f1df8a939342b16c0e7337cd393527d7.tar.gz
rust-5855e0a2f1df8a939342b16c0e7337cd393527d7.zip
Small refactoring: irrefutable let pattern
-rw-r--r--clippy_lints/src/methods/sliced_string_as_bytes.rs29
1 files changed, 14 insertions, 15 deletions
diff --git a/clippy_lints/src/methods/sliced_string_as_bytes.rs b/clippy_lints/src/methods/sliced_string_as_bytes.rs
index 43aab8a452e..eb080ebe21d 100644
--- a/clippy_lints/src/methods/sliced_string_as_bytes.rs
+++ b/clippy_lints/src/methods/sliced_string_as_bytes.rs
@@ -10,21 +10,20 @@ use super::SLICED_STRING_AS_BYTES;
 pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>) {
     if let ExprKind::Index(indexed, index, _) = recv.kind
         && is_range_literal(index)
+        && let ty = cx.typeck_results().expr_ty(indexed).peel_refs()
+        && (ty.is_str() || is_type_lang_item(cx, ty, LangItem::String))
     {
-        let ty = cx.typeck_results().expr_ty(indexed).peel_refs();
-        if ty.is_str() || is_type_lang_item(cx, ty, LangItem::String) {
-            let mut applicability = Applicability::MaybeIncorrect;
-            let stringish = snippet_with_applicability(cx, indexed.span, "..", &mut applicability);
-            let range = snippet_with_applicability(cx, index.span, "..", &mut applicability);
-            span_lint_and_sugg(
-                cx,
-                SLICED_STRING_AS_BYTES,
-                expr.span,
-                "calling `as_bytes` after slicing a string",
-                "try",
-                format!("&{stringish}.as_bytes()[{range}]"),
-                applicability,
-            );
-        }
+        let mut applicability = Applicability::MaybeIncorrect;
+        let stringish = snippet_with_applicability(cx, indexed.span, "..", &mut applicability);
+        let range = snippet_with_applicability(cx, index.span, "..", &mut applicability);
+        span_lint_and_sugg(
+            cx,
+            SLICED_STRING_AS_BYTES,
+            expr.span,
+            "calling `as_bytes` after slicing a string",
+            "try",
+            format!("&{stringish}.as_bytes()[{range}]"),
+            applicability,
+        );
     }
 }