Accounted for possible extra layers before the consuming parent expr

This commit is contained in:
schvv31n 2024-05-20 21:27:30 +01:00
parent 3955bd4c98
commit b31625cdc7
3 changed files with 12 additions and 2 deletions

View File

@ -77,11 +77,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method
.qpath_res(path, *hir_id)
.opt_def_id()
.filter(|fn_id| cx.tcx.def_kind(fn_id).is_fn_like())
.is_some_and(|fn_id| is_arg_ty_unified_in_fn(cx, fn_id, expr.hir_id, args)),
.is_some_and(|fn_id| is_arg_ty_unified_in_fn(cx, fn_id, child_id, args)),
ExprKind::MethodCall(_name, recv, args, _span) => is_arg_ty_unified_in_fn(
cx,
cx.typeck_results().type_dependent_def_id(parent.hir_id).unwrap(),
expr.hir_id,
child_id,
once(recv).chain(args.iter()),
),
ExprKind::If(_, _, _)

View File

@ -29,6 +29,11 @@ fn array() {
println!("{i}");
}
// Same as above, but for empty collection iters with extra layers
for i in smth.as_ref().map_or({ [].iter() }, |s| s.iter()) {
println!("{y}", y = i + 1);
}
// Same as above, but for regular function calls
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
println!("{i}");

View File

@ -29,6 +29,11 @@ fn array() {
println!("{i}");
}
// Same as above, but for empty collection iters with extra layers
for i in smth.as_ref().map_or({ [].iter() }, |s| s.iter()) {
println!("{y}", y = i + 1);
}
// Same as above, but for regular function calls
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
println!("{i}");