Skip to content

Commit 6941952

Browse files
committed
Minor refactoring to satisfy clippy
1 parent 2e9ec3a commit 6941952

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,24 @@ fn extract_count_with_applicability(
2727
if let ExprKind::Lit(lit) = end.kind
2828
&& let LitKind::Int(Pu128(upper_bound), _) = lit.node
2929
{
30-
let count = if range.limits == RangeLimits::Closed {
31-
upper_bound - lower_bound + 1
32-
} else {
33-
upper_bound - lower_bound
34-
};
35-
return Some(format!("{count}"));
36-
} else {
37-
let end_snippet = snippet_with_applicability(cx, end.span, "...", applicability).into_owned();
38-
if lower_bound == 0 {
39-
if range.limits == RangeLimits::Closed {
40-
return Some(format!("{end_snippet} + 1"));
41-
} else {
42-
return Some(end_snippet);
43-
};
30+
// Here we can explicitly calculate the number of iterations
31+
let mut count = upper_bound - lower_bound;
32+
if range.limits == RangeLimits::Closed {
33+
count += 1;
4434
}
35+
return Some(format!("{count}"));
36+
}
37+
let end_snippet = snippet_with_applicability(cx, end.span, "...", applicability).into_owned();
38+
if lower_bound == 0 {
4539
if range.limits == RangeLimits::Closed {
46-
if lower_bound > 0 {
47-
return Some(format!("{end_snippet} - {}", lower_bound - 1));
48-
}
4940
return Some(format!("{end_snippet} + 1"));
50-
} else {
51-
return Some(format!("{end_snippet} - {lower_bound}"));
52-
};
41+
}
42+
return Some(end_snippet);
43+
}
44+
if range.limits == RangeLimits::Closed {
45+
return Some(format!("{end_snippet} - {}", lower_bound - 1));
5346
}
47+
return Some(format!("{end_snippet} - {lower_bound}"));
5448
}
5549
None
5650
}

0 commit comments

Comments
 (0)