Skip to content

Commit 90a5118

Browse files
Fix false positive in PartialEq implementation
1 parent 7e650b7 commit 90a5118

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

clippy_lints/src/unconditional_recursion.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,18 @@ impl<'tcx> LateLintPass<'tcx> for UnconditionalRecursion {
102102
let expr = body.value.peel_blocks();
103103
let is_bad = match expr.kind {
104104
ExprKind::Binary(op, left, right) if op.node == to_check_op => {
105-
is_local(cx, left) && is_local(cx, right)
105+
// First we check both are local variables.
106+
if is_local(cx, left)
107+
&& is_local(cx, right)
108+
// Then we check if the left-hand element is of the same type as `self`.
109+
&& let Some(left_ty) = cx.typeck_results().expr_ty_opt(left)
110+
&& let Some(left_id) = get_ty_def_id(left_ty)
111+
&& self_arg == left_id
112+
{
113+
true
114+
} else {
115+
false
116+
}
106117
},
107118
ExprKind::MethodCall(segment, receiver, &[arg], _) if segment.ident.name == name.name => {
108119
if is_local(cx, receiver)

0 commit comments

Comments
 (0)