about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs3
-rw-r--r--tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.rs8
-rw-r--r--tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.stderr14
3 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
index 16294970f05..928010c03c2 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
@@ -185,6 +185,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         rhs_ty: Ty<'tcx>,
         can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool,
     ) -> bool {
+        if lhs_expr.span.in_derive_expansion() || rhs_expr.span.in_derive_expansion() {
+            return false;
+        }
         let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else {
             return false;
         };
diff --git a/tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.rs b/tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.rs
new file mode 100644
index 00000000000..76b93c0c947
--- /dev/null
+++ b/tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.rs
@@ -0,0 +1,8 @@
+use std::rc::Rc;
+
+#[derive(PartialEq)] //~ NOTE in this expansion
+pub struct Function {
+    callback: Rc<dyn Fn()>, //~ ERROR binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
+}
+
+fn main() {}
diff --git a/tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.stderr b/tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.stderr
new file mode 100644
index 00000000000..40464a49c34
--- /dev/null
+++ b/tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.stderr
@@ -0,0 +1,14 @@
+error[E0369]: binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
+  --> $DIR/do-not-suggest-calling-fn-in-derive-macro.rs:5:5
+   |
+LL | #[derive(PartialEq)]
+   |          --------- in this derive macro expansion
+LL | pub struct Function {
+LL |     callback: Rc<dyn Fn()>,
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0369`.