about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/noop_method_call.rs
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-02-22 18:01:12 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-02-22 18:01:20 +0000
commit6017de46f7864cabcf4770f11c93f319314a250f (patch)
treeb0ba57be3d7d0021274e90ef927bb81cb111252b /compiler/rustc_lint/src/noop_method_call.rs
parent2dc0170233689435f988579a2080f27b02027d21 (diff)
downloadrust-6017de46f7864cabcf4770f11c93f319314a250f.tar.gz
rust-6017de46f7864cabcf4770f11c93f319314a250f.zip
When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`
CC #40699.
Diffstat (limited to 'compiler/rustc_lint/src/noop_method_call.rs')
-rw-r--r--compiler/rustc_lint/src/noop_method_call.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs
index 26c5e4fb483..970d411fb06 100644
--- a/compiler/rustc_lint/src/noop_method_call.rs
+++ b/compiler/rustc_lint/src/noop_method_call.rs
@@ -121,10 +121,20 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
         let orig_ty = expr_ty.peel_refs();
 
         if receiver_ty == expr_ty {
+            let suggest_derive = match orig_ty.kind() {
+                ty::Adt(def, _) => Some(cx.tcx.def_span(def.did()).shrink_to_lo()),
+                _ => None,
+            };
             cx.emit_span_lint(
                 NOOP_METHOD_CALL,
                 span,
-                NoopMethodCallDiag { method: call.ident.name, orig_ty, trait_, label: span },
+                NoopMethodCallDiag {
+                    method: call.ident.name,
+                    orig_ty,
+                    trait_,
+                    label: span,
+                    suggest_derive,
+                },
             );
         } else {
             match name {