Skip to content

Commit f410df3

Browse files
committed
make clippy happy (needless_pass_by_value, filter_map and find_map)
1 parent 4418738 commit f410df3

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
@@ -952,7 +952,13 @@ fn get_details_from_idx<'tcx>(
952952
e: &Expr<'_>,
953953
starts: &[Start<'tcx>],
954954
) -> Option<StartKind<'tcx>> {
955-
starts.iter().find(|var| same_var(cx, e, var.id)).map(|v| v.kind)
955+
starts.iter().find_map(|start| {
956+
if same_var(cx, e, start.id) {
957+
Some(start.kind)
958+
} else {
959+
None
960+
}
961+
})
956962
}
957963

958964
fn get_offset<'tcx>(
@@ -1059,8 +1065,8 @@ fn build_manual_memcpy_suggestion<'tcx>(
10591065
start: &Expr<'_>,
10601066
end: &Expr<'_>,
10611067
limits: ast::RangeLimits,
1062-
dst: IndexExpr<'_>,
1063-
src: IndexExpr<'_>,
1068+
dst: &IndexExpr<'_>,
1069+
src: &IndexExpr<'_>,
10641070
) -> String {
10651071
fn print_offset(offset: MinifyingSugg<'static>) -> MinifyingSugg<'static> {
10661072
if offset.as_str() == "0" {
@@ -1211,7 +1217,7 @@ fn detect_manual_memcpy<'tcx>(
12111217
}
12121218
})
12131219
})
1214-
.map(|o| o.map(|(dst, src)| build_manual_memcpy_suggestion(cx, start, end, limits, dst, src)))
1220+
.map(|o| o.map(|(dst, src)| build_manual_memcpy_suggestion(cx, start, end, limits, &dst, &src)))
12151221
.collect::<Option<Vec<_>>>()
12161222
.filter(|v| !v.is_empty())
12171223
.map(|v| v.join("\n "));
@@ -2319,10 +2325,13 @@ impl<'a, 'tcx> IncrementVisitor<'a, 'tcx> {
23192325
}
23202326

23212327
fn into_results(self) -> impl Iterator<Item = HirId> {
2322-
self.states
2323-
.into_iter()
2324-
.filter(|(_, state)| *state == IncrementVisitorVarState::IncrOnce)
2325-
.map(|(id, _)| id)
2328+
self.states.into_iter().filter_map(|(id, state)| {
2329+
if state == IncrementVisitorVarState::IncrOnce {
2330+
Some(id)
2331+
} else {
2332+
None
2333+
}
2334+
})
23262335
}
23272336
}
23282337

0 commit comments

Comments
 (0)