Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cyrgani opened this issue Jan 24, 2025 · 0 comments · Fixed by #136027
Closed

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

cyrgani opened this issue Jan 24, 2025 · 0 comments · Fixed by #136027
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Jan 24, 2025

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

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 24, 2025
@rustbot rustbot added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jan 24, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2025
…errors

Skip suggestions in `derive`d code

Do not suggest

```
help: use parentheses to call these
  |
5 |     (callback: Rc<dyn Fn()>)(),
  |     +                      +++
```

Skip all "call function for this binop" suggestions when in a derive context.

Fix rust-lang#135989.
@bors bors closed this as completed in 8873c18 Jan 25, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 25, 2025
Rollup merge of rust-lang#136027 - estebank:issue-135989, r=compiler-errors

Skip suggestions in `derive`d code

Do not suggest

```
help: use parentheses to call these
  |
5 |     (callback: Rc<dyn Fn()>)(),
  |     +                      +++
```

Skip all "call function for this binop" suggestions when in a derive context.

Fix rust-lang#135989.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants