Skip to content

Commit 25f5006

Browse files
committed
style: use zip-the-function all over the place
makes the code a bit more concise by removing the need for explicit `.iter()`
1 parent 3908154 commit 25f5006

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

clippy_utils/src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub use self::hir_utils::{
8484
use core::mem;
8585
use core::ops::ControlFlow;
8686
use std::collections::hash_map::Entry;
87-
use std::iter::{once, repeat_n};
87+
use std::iter::{once, repeat_n, zip};
8888
use std::sync::{Mutex, MutexGuard, OnceLock};
8989

9090
use itertools::Itertools;
@@ -581,7 +581,7 @@ pub fn can_mut_borrow_both(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>) -
581581
return false;
582582
}
583583

584-
for (x1, x2) in s1.iter().zip(s2.iter()) {
584+
for (x1, x2) in zip(&s1, &s2) {
585585
if expr_custom_deref_adjustment(cx, x1).is_some() || expr_custom_deref_adjustment(cx, x2).is_some() {
586586
return false;
587587
}
@@ -1923,24 +1923,20 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool {
19231923
(PatKind::Tuple(pats, dotdot), ExprKind::Tup(tup))
19241924
if dotdot.as_opt_usize().is_none() && pats.len() == tup.len() =>
19251925
{
1926-
pats.iter().zip(tup).all(|(pat, expr)| check_pat(cx, pat, expr))
1926+
zip(pats, tup).all(|(pat, expr)| check_pat(cx, pat, expr))
19271927
},
19281928
(PatKind::Slice(before, slice, after), ExprKind::Array(arr))
19291929
if slice.is_none() && before.len() + after.len() == arr.len() =>
19301930
{
1931-
(before.iter().chain(after))
1932-
.zip(arr)
1933-
.all(|(pat, expr)| check_pat(cx, pat, expr))
1931+
zip(before.iter().chain(after), arr).all(|(pat, expr)| check_pat(cx, pat, expr))
19341932
},
19351933
(PatKind::TupleStruct(pat_ident, field_pats, dotdot), ExprKind::Call(ident, fields))
19361934
if dotdot.as_opt_usize().is_none()
19371935
&& let ExprKind::Path(ident) = ident.kind =>
19381936
{
19391937
field_pats.len() == fields.len()
19401938
&& qpath_res(&pat_ident, pat.hir_id) == qpath_res(&ident, expr.hir_id)
1941-
&& (field_pats.iter())
1942-
.zip(fields)
1943-
.all(|(pat, expr)| check_pat(cx, pat, expr))
1939+
&& zip(field_pats, fields).all(|(pat, expr)| check_pat(cx, pat, expr))
19441940
},
19451941
(
19461942
PatKind::Struct(pat_ident, field_pats, false),

0 commit comments

Comments
 (0)