mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Accounted for possible extra layers before the consuming parent expr
This commit is contained in:
parent
3955bd4c98
commit
b31625cdc7
3 changed files with 12 additions and 2 deletions
|
@ -77,11 +77,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, method
|
||||||
.qpath_res(path, *hir_id)
|
.qpath_res(path, *hir_id)
|
||||||
.opt_def_id()
|
.opt_def_id()
|
||||||
.filter(|fn_id| cx.tcx.def_kind(fn_id).is_fn_like())
|
.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(
|
ExprKind::MethodCall(_name, recv, args, _span) => is_arg_ty_unified_in_fn(
|
||||||
cx,
|
cx,
|
||||||
cx.typeck_results().type_dependent_def_id(parent.hir_id).unwrap(),
|
cx.typeck_results().type_dependent_def_id(parent.hir_id).unwrap(),
|
||||||
expr.hir_id,
|
child_id,
|
||||||
once(recv).chain(args.iter()),
|
once(recv).chain(args.iter()),
|
||||||
),
|
),
|
||||||
ExprKind::If(_, _, _)
|
ExprKind::If(_, _, _)
|
||||||
|
|
|
@ -29,6 +29,11 @@ fn array() {
|
||||||
println!("{i}");
|
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
|
// Same as above, but for regular function calls
|
||||||
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
|
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
|
||||||
println!("{i}");
|
println!("{i}");
|
||||||
|
|
|
@ -29,6 +29,11 @@ fn array() {
|
||||||
println!("{i}");
|
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
|
// Same as above, but for regular function calls
|
||||||
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
|
for i in Option::map_or(smth.as_ref(), [].iter(), |s| s.iter()) {
|
||||||
println!("{i}");
|
println!("{i}");
|
||||||
|
|
Loading…
Reference in a new issue