Skip to content

Commit c8cd09a

Browse files
Fix false positive in PartialEq check in unconditional_recursion lint
1 parent 74db4b7 commit c8cd09a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

clippy_lints/src/unconditional_recursion.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,15 @@ fn check_partial_eq(cx: &LateContext<'_>, method_span: Span, method_def_id: Loca
167167
false
168168
}
169169
},
170-
ExprKind::MethodCall(segment, _receiver, &[_arg], _) if segment.ident.name == name.name => {
170+
ExprKind::MethodCall(segment, receiver, &[_arg], _) if segment.ident.name == name.name => {
171+
if let Some(ty) = cx.typeck_results().expr_ty_opt(receiver)
172+
&& let Some(ty_id) = get_ty_def_id(ty)
173+
&& self_arg != ty_id
174+
{
175+
// Since this called on a different type, the lint should not be
176+
// triggered here.
177+
return;
178+
}
171179
if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
172180
&& let Some(trait_id) = cx.tcx.trait_of_item(fn_id)
173181
&& trait_id == trait_def_id

0 commit comments

Comments
 (0)