Skip to content

Commit 6647b99

Browse files
committed
Fix noop_method_call detection for new diagnostic items
1 parent 92009f2 commit 6647b99

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/rustc_lint/src/noop_method_call.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
114114

115115
let orig_ty = expr_ty.peel_refs();
116116

117-
if receiver_ty == expr_ty {
117+
if receiver_ty == expr_ty
118+
&& matches!(
119+
name,
120+
sym::noop_method_borrow | sym::noop_method_clone | sym::noop_method_deref
121+
)
122+
{
118123
cx.emit_spanned_lint(
119124
NOOP_METHOD_CALL,
120125
span,

tests/ui/lint/noop-method-call.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-pass
22
// run-rustfix
33

4+
#![feature(rustc_attrs)]
45
#![allow(unused)]
56

67
use std::borrow::Borrow;
@@ -49,3 +50,15 @@ fn non_generic(non_clone_type: &PlainType<u32>) {
4950
non_clone_type.clone();
5051
//~^ WARN call to `.clone()` on a reference in this situation does nothing
5152
}
53+
54+
struct DiagnosticClone;
55+
impl Clone for DiagnosticClone {
56+
#[rustc_diagnostic_item = "other_clone"]
57+
fn clone(&self) -> Self {
58+
DiagnosticClone
59+
}
60+
}
61+
62+
fn with_other_diagnostic_item(x: DiagnosticClone) {
63+
x.clone();
64+
}

0 commit comments

Comments
 (0)