Skip to content

Commit 8bae279

Browse files
committed
remove if_chain
1 parent cc2b000 commit 8bae279

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

clippy_lints/src/methods/iter_count.rs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,38 @@ pub(crate) fn lints<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, iter_args: &'
2121
return;
2222
};
2323
let ty = cx.typeck_results().expr_ty(&iter_args[0]);
24-
if_chain! {
25-
let caller_type = if derefs_to_slice(cx, &iter_args[0], ty).is_some() {
26-
"slice"
27-
} else if is_type_diagnostic_item(cx, ty, sym::vec_type) {
28-
"Vec"
29-
} else if is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) {
30-
"VecDeque"
31-
} else if is_type_diagnostic_item(cx, ty, sym!(hashset_type)) {
32-
"HashSet"
33-
} else if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) {
34-
"HashMap"
35-
} else if match_type(cx, ty, &paths::BTREEMAP) {
36-
"BTreeMap"
37-
} else if match_type(cx, ty, &paths::BTREESET) {
38-
"BTreeSet"
39-
} else if match_type(cx, ty, &paths::LINKED_LIST) {
40-
"LinkedList"
41-
} else if match_type(cx, ty, &paths::BINARY_HEAP) {
42-
"BinaryHeap"
43-
} else {
44-
return
45-
};
46-
then {
47-
let mut applicability = Applicability::MachineApplicable;
48-
span_lint_and_sugg(
49-
cx,
50-
ITER_COUNT,
51-
expr.span,
52-
&format!("called `.{}{}().count()` on a `{}`", iter_method, mut_str, caller_type),
53-
"try",
54-
format!(
55-
"{}.len()",
56-
snippet_with_applicability(cx, iter_args[0].span, "..", &mut applicability),
57-
),
58-
applicability,
59-
);
60-
}
61-
}
24+
let caller_type = if derefs_to_slice(cx, &iter_args[0], ty).is_some() {
25+
"slice"
26+
} else if is_type_diagnostic_item(cx, ty, sym::vec_type) {
27+
"Vec"
28+
} else if is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) {
29+
"VecDeque"
30+
} else if is_type_diagnostic_item(cx, ty, sym!(hashset_type)) {
31+
"HashSet"
32+
} else if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) {
33+
"HashMap"
34+
} else if match_type(cx, ty, &paths::BTREEMAP) {
35+
"BTreeMap"
36+
} else if match_type(cx, ty, &paths::BTREESET) {
37+
"BTreeSet"
38+
} else if match_type(cx, ty, &paths::LINKED_LIST) {
39+
"LinkedList"
40+
} else if match_type(cx, ty, &paths::BINARY_HEAP) {
41+
"BinaryHeap"
42+
} else {
43+
return;
44+
};
45+
let mut applicability = Applicability::MachineApplicable;
46+
span_lint_and_sugg(
47+
cx,
48+
ITER_COUNT,
49+
expr.span,
50+
&format!("called `.{}{}().count()` on a `{}`", iter_method, mut_str, caller_type),
51+
"try",
52+
format!(
53+
"{}.len()",
54+
snippet_with_applicability(cx, iter_args[0].span, "..", &mut applicability),
55+
),
56+
applicability,
57+
);
6258
}

0 commit comments

Comments
 (0)