Auto merge of #12615 - Kobzol:fix-recursive-clone-from, r=blyxyas
Do not suggest `assigning_clones` in `Clone` impl This PR modifies `assigning_clones` to detect situations where the `clone` call is inside a `Clone` impl, and avoids suggesting the lint in such situations. r? `@blyxyas` Fixes: https://github.com/rust-lang/rust-clippy/issues/12600 changelog: Do not invoke `assigning_clones` inside `Clone` impl
This commit is contained in:
commit
e80ca2f381
4 changed files with 49 additions and 6 deletions
|
|
@ -181,6 +181,23 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC
|
|||
return false;
|
||||
}
|
||||
|
||||
// If the call expression is inside an impl block that contains the method invoked by the
|
||||
// call expression, we bail out to avoid suggesting something that could result in endless
|
||||
// recursion.
|
||||
if let Some(local_block_id) = impl_block.as_local()
|
||||
&& let Some(block) = cx.tcx.hir_node_by_def_id(local_block_id).as_owner()
|
||||
{
|
||||
let impl_block_owner = block.def_id();
|
||||
if cx
|
||||
.tcx
|
||||
.hir()
|
||||
.parent_id_iter(lhs.hir_id)
|
||||
.any(|parent| parent.owner == impl_block_owner)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Find the function for which we want to check that it is implemented.
|
||||
let provided_fn = match call.target {
|
||||
TargetTrait::Clone => cx.tcx.get_diagnostic_item(sym::Clone).and_then(|clone| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue