Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5855e0a

Browse files
committed
Small refactoring: irrefutable let pattern
1 parent 4fef1b4 commit 5855e0a

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

clippy_lints/src/methods/sliced_string_as_bytes.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ use super::SLICED_STRING_AS_BYTES;
1010
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>) {
1111
if let ExprKind::Index(indexed, index, _) = recv.kind
1212
&& is_range_literal(index)
13+
&& let ty = cx.typeck_results().expr_ty(indexed).peel_refs()
14+
&& (ty.is_str() || is_type_lang_item(cx, ty, LangItem::String))
1315
{
14-
let ty = cx.typeck_results().expr_ty(indexed).peel_refs();
15-
if ty.is_str() || is_type_lang_item(cx, ty, LangItem::String) {
16-
let mut applicability = Applicability::MaybeIncorrect;
17-
let stringish = snippet_with_applicability(cx, indexed.span, "..", &mut applicability);
18-
let range = snippet_with_applicability(cx, index.span, "..", &mut applicability);
19-
span_lint_and_sugg(
20-
cx,
21-
SLICED_STRING_AS_BYTES,
22-
expr.span,
23-
"calling `as_bytes` after slicing a string",
24-
"try",
25-
format!("&{stringish}.as_bytes()[{range}]"),
26-
applicability,
27-
);
28-
}
16+
let mut applicability = Applicability::MaybeIncorrect;
17+
let stringish = snippet_with_applicability(cx, indexed.span, "..", &mut applicability);
18+
let range = snippet_with_applicability(cx, index.span, "..", &mut applicability);
19+
span_lint_and_sugg(
20+
cx,
21+
SLICED_STRING_AS_BYTES,
22+
expr.span,
23+
"calling `as_bytes` after slicing a string",
24+
"try",
25+
format!("&{stringish}.as_bytes()[{range}]"),
26+
applicability,
27+
);
2928
}
3029
}

0 commit comments

Comments
 (0)