Skip to content

Commit af44a07

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 2943a7f commit af44a07

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

clippy_utils/src/lib.rs

Lines changed: 5 additions & 11 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;
@@ -582,7 +582,7 @@ pub fn can_mut_borrow_both(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>) -
582582
return false;
583583
}
584584

585-
for (x1, x2) in s1.iter().zip(s2.iter()) {
585+
for (x1, x2) in zip(&s1, &s2) {
586586
if expr_custom_deref_adjustment(cx, x1).is_some() || expr_custom_deref_adjustment(cx, x2).is_some() {
587587
return false;
588588
}
@@ -1975,26 +1975,20 @@ pub fn is_expr_identity_of_pat(cx: &LateContext<'_>, pat: &Pat<'_>, expr: &Expr<
19751975
(PatKind::Tuple(pats, dotdot), ExprKind::Tup(tup))
19761976
if dotdot.as_opt_usize().is_none() && pats.len() == tup.len() =>
19771977
{
1978-
pats.iter()
1979-
.zip(tup)
1980-
.all(|(pat, expr)| is_expr_identity_of_pat(cx, pat, expr, by_hir))
1978+
zip(pats, tup).all(|(pat, expr)| is_expr_identity_of_pat(cx, pat, expr, by_hir))
19811979
},
19821980
(PatKind::Slice(before, slice, after), ExprKind::Array(arr))
19831981
if slice.is_none() && before.len() + after.len() == arr.len() =>
19841982
{
1985-
(before.iter().chain(after))
1986-
.zip(arr)
1987-
.all(|(pat, expr)| is_expr_identity_of_pat(cx, pat, expr, by_hir))
1983+
zip(before.iter().chain(after), arr).all(|(pat, expr)| is_expr_identity_of_pat(cx, pat, expr, by_hir))
19881984
},
19891985
(PatKind::TupleStruct(pat_ident, field_pats, dotdot), ExprKind::Call(ident, fields))
19901986
if dotdot.as_opt_usize().is_none()
19911987
&& let ExprKind::Path(ident) = ident.kind =>
19921988
{
19931989
field_pats.len() == fields.len()
19941990
&& qpath_res(&pat_ident, pat.hir_id) == qpath_res(&ident, expr.hir_id)
1995-
&& (field_pats.iter())
1996-
.zip(fields)
1997-
.all(|(pat, expr)| is_expr_identity_of_pat(cx, pat, expr, by_hir))
1991+
&& zip(field_pats, fields).all(|(pat, expr)| is_expr_identity_of_pat(cx, pat, expr, by_hir))
19981992
},
19991993
(PatKind::Struct(pat_ident, field_pats, false), ExprKind::Struct(ident, fields, hir::StructTailExpr::None)) => {
20001994
field_pats.len() == fields.len()

0 commit comments

Comments
 (0)