Skip to content

Suggestion for deriving PartialEq on a type containing dyn Fn() is very invalid #135989

Closed
@cyrgani

Description

@cyrgani

Code

use std::rc::Rc;

#[derive(PartialEq)]
pub struct Function {
    callback: Rc<dyn Fn()>,
}

Current output

error[E0369]: binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
 --> src/lib.rs:5:5
  |
3 | #[derive(PartialEq)]
  |          --------- in this derive macro expansion
4 | pub struct Function {
5 |     callback: Rc<dyn Fn()>,
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use parentheses to call these
  |
5 |     (callback: Rc<dyn Fn()>)(),
  |     +                      +++

Desired output

error[E0369]: binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
 --> src/lib.rs:5:5
  |
3 | #[derive(PartialEq)]
  |          --------- in this derive macro expansion
4 | pub struct Function {
5 |     callback: Rc<dyn Fn()>,
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

Rationale and extra context

No response

Other cases

Rust Version

1.86.0-nightly (2025-01-23 99768c80a1c094a5cfc3)

Anything else?

@rustbot label D-incorrect D-invalid-suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions