summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2021-03-14 01:18:04 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2021-03-18 00:51:18 +0900
commit0c81311bf0093e991c0b5ca8b69096a5c5cd161c (patch)
tree3c1db051dae56907ca96d05f0a82763b5a59510b
parentf0a101d81dc25fae998d0670348d928f1789439b (diff)
downloadrust-0c81311bf0093e991c0b5ca8b69096a5c5cd161c.tar.gz
extract a condition into a function.
-rw-r--r--clippy_lints/src/methods/iter_next_slice.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/clippy_lints/src/methods/iter_next_slice.rs b/clippy_lints/src/methods/iter_next_slice.rs
index 869b2cdd1a6..2155159bf7c 100644
--- a/clippy_lints/src/methods/iter_next_slice.rs
+++ b/clippy_lints/src/methods/iter_next_slice.rs
@@ -47,12 +47,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, ite
);
}
}
- } else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(caller_expr), sym::vec_type)
- || matches!(
- &cx.typeck_results().expr_ty(caller_expr).peel_refs().kind(),
- ty::Array(_, _)
- )
- {
+ } else if is_vec_or_array(cx, caller_expr) {
// caller is a Vec or an Array
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
@@ -69,3 +64,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, ite
);
}
}
+
+fn is_vec_or_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) -> bool {
+ is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type)
+ || matches!(&cx.typeck_results().expr_ty(expr).peel_refs().kind(), ty::Array(_, _))
+}