Skip to content

Commit 3629372

Browse files
Lint on closure calls, suppress on callable constants calls
1 parent 9d311b5 commit 3629372

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

clippy_lints/src/methods/iter_on_single_or_empty_collections.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ fn is_arg_ty_unified_in_fn<'tcx>(
3333
cx: &LateContext<'tcx>,
3434
fn_id: DefId,
3535
arg_id: HirId,
36-
args: impl Iterator<Item = &'tcx Expr<'tcx>> + Clone,
36+
args: impl IntoIterator<Item = &'tcx Expr<'tcx>>,
3737
) -> bool {
3838
let fn_sig = cx.tcx.fn_sig(fn_id).instantiate_identity();
39-
let arg_id_in_args = args.clone().position(|e| e.hir_id == arg_id).unwrap();
39+
let arg_id_in_args = args.into_iter().position(|e| e.hir_id == arg_id).unwrap();
4040
let arg_ty_in_args = fn_sig.input(arg_id_in_args);
4141

4242
cx.tcx.predicates_of(fn_id).predicates.iter().any(|(clause, _)| {
@@ -72,12 +72,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method
7272
..
7373
},
7474
args,
75-
) => is_arg_ty_unified_in_fn(
76-
cx,
77-
cx.typeck_results().qpath_res(path, *hir_id).def_id(),
78-
expr.hir_id,
79-
args.iter(),
80-
),
75+
) => {
76+
cx.typeck_results().qpath_res(path, *hir_id).opt_def_id()
77+
.filter(|fn_id| cx.tcx.def_kind(fn_id).is_fn_like())
78+
.is_some_and(|fn_id| is_arg_ty_unified_in_fn(cx, fn_id, expr.hir_id, args))
79+
}
8180
ExprKind::MethodCall(_name, recv, args, _span) => is_arg_ty_unified_in_fn(
8281
cx,
8382
cx.typeck_results().type_dependent_def_id(parent.hir_id).unwrap(),

0 commit comments

Comments
 (0)