Do not warn on .map(_::clone) for Arc, Rc, and their weak variants

Those constructions are idiomatic, and using `Arc::clone(x)` and
`Rc::clone(x)` is often the recommended way of cloning a `Arc` or a
`Rc`.
This commit is contained in:
Samuel Tardieu 2024-03-22 00:33:31 +01:00
parent 9d6f41691e
commit 7c9fe30ce4
3 changed files with 53 additions and 0 deletions

View file

@ -124,6 +124,11 @@ fn handle_path(
&& let ty::Ref(_, ty, Mutability::Not) = ty.kind()
&& let ty::FnDef(_, lst) = cx.typeck_results().expr_ty(arg).kind()
&& lst.iter().all(|l| l.as_type() == Some(*ty))
&& !matches!(
ty.ty_adt_def()
.and_then(|adt_def| cx.tcx.get_diagnostic_name(adt_def.did())),
Some(sym::Arc | sym::ArcWeak | sym::Rc | sym::RcWeak)
)
{
lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs()));
}