Skip to content

Commit 20a4453

Browse files
committed
make clippy happy (needless_pass_by_value, filter_map and find_map)
1 parent 9f2d0a6 commit 20a4453

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

clippy_lints/src/loops.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,13 @@ fn get_details_from_idx<'a, 'tcx>(
921921
e: &Expr<'_>,
922922
starts: &[Start<'tcx>],
923923
) -> Option<StartKind<'tcx>> {
924-
starts.iter().find(|var| same_var(cx, e, var.id)).map(|v| v.kind)
924+
starts.iter().find_map(|start| {
925+
if same_var(cx, e, start.id) {
926+
Some(start.kind)
927+
} else {
928+
None
929+
}
930+
})
925931
}
926932

927933
fn get_offset<'a, 'tcx>(
@@ -1028,8 +1034,8 @@ fn build_manual_memcpy_suggestion<'a, 'tcx>(
10281034
start: &Expr<'_>,
10291035
end: &Expr<'_>,
10301036
limits: ast::RangeLimits,
1031-
dst: IndexExpr<'_>,
1032-
src: IndexExpr<'_>,
1037+
dst: &IndexExpr<'_>,
1038+
src: &IndexExpr<'_>,
10331039
) -> String {
10341040
fn print_offset(offset: MinifyingSugg<'static>) -> MinifyingSugg<'static> {
10351041
if offset.as_str() == "0" {
@@ -1180,7 +1186,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
11801186
}
11811187
})
11821188
})
1183-
.map(|o| o.map(|(dst, src)| build_manual_memcpy_suggestion(cx, start, end, limits, dst, src)))
1189+
.map(|o| o.map(|(dst, src)| build_manual_memcpy_suggestion(cx, start, end, limits, &dst, &src)))
11841190
.collect::<Option<Vec<_>>>()
11851191
.filter(|v| !v.is_empty())
11861192
.map(|v| v.join("\n "));
@@ -2129,10 +2135,13 @@ impl<'a, 'tcx> IncrementVisitor<'a, 'tcx> {
21292135
}
21302136

21312137
fn into_results(self) -> impl Iterator<Item = HirId> {
2132-
self.states
2133-
.into_iter()
2134-
.filter(|(_, state)| *state == IncrementVisitorVarState::IncrOnce)
2135-
.map(|(id, _)| id)
2138+
self.states.into_iter().filter_map(|(id, state)| {
2139+
if state == IncrementVisitorVarState::IncrOnce {
2140+
Some(id)
2141+
} else {
2142+
None
2143+
}
2144+
})
21362145
}
21372146
}
21382147

0 commit comments

Comments
 (0)