diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index bc0b9d6d81871..68a4b1397cc79 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -114,7 +114,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { let orig_ty = expr_ty.peel_refs(); - if receiver_ty == expr_ty { + if receiver_ty == expr_ty + && matches!( + name, + sym::noop_method_borrow | sym::noop_method_clone | sym::noop_method_deref + ) + { cx.emit_spanned_lint( NOOP_METHOD_CALL, span, diff --git a/tests/ui/lint/noop-method-call.rs b/tests/ui/lint/noop-method-call.rs index 9569a0dfc617e..8420f68071399 100644 --- a/tests/ui/lint/noop-method-call.rs +++ b/tests/ui/lint/noop-method-call.rs @@ -49,3 +49,15 @@ fn non_generic(non_clone_type: &PlainType) { non_clone_type.clone(); //~^ WARN call to `.clone()` on a reference in this situation does nothing } + +struct DiagnosticClone; +impl Clone for DiagnosticClone { + #[rustc_diagnostic_item = "other_clone"] + fn clone(&self) -> Self { + *self + } +} + +fn with_other_diagnostic_item(x: &DiagnosticClone) { + x.clone(); +}