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

misleading "add dyn keyword before derive macro" suggestion #106071

Closed
eopb opened this issue Dec 23, 2022 · 1 comment · Fixed by #106072
Closed

misleading "add dyn keyword before derive macro" suggestion #106071

eopb opened this issue Dec 23, 2022 · 1 comment · Fixed by #106072
Assignees
Labels
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.

Comments

@eopb
Copy link
Contributor

eopb commented Dec 23, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=340b1d1f9850c0644977b8c47b00dc77

#[derive(Clone)]
struct Debug;
trait Debug {}

The current output is:

error[[E0428]](https://doc.rust-lang.org/stable/error-index.html#E0428): the name `Debug` is defined multiple times
 --> src/lib.rs:3:1
  |
2 | struct Debug;
  | ------------- previous definition of the type `Debug` here
3 | trait Debug {}
  | ^^^^^^^^^^^ `Debug` redefined here
  |
  = note: `Debug` must be defined only once in the type namespace of this module

error[[E0782]](https://doc.rust-lang.org/stable/error-index.html#E0782): trait objects must include the `dyn` keyword
 --> src/lib.rs:1:10
  |
1 | #[derive(Clone)]
  |          ^^^^^
  |
  = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add `dyn` keyword before this trait
  |
1 | #[derive(dyn Clone)]
  |          +++

Some errors have detailed explanations: E0428, E0782.
For more information about an error, try `rustc --explain E0428`.

Ideally the output should not suggest placing dyn before Clone in #[derive(Clone)] because the dyn keyword is not valid in that position.

Thank you to @conradludgate for finding the minimum reproducible that I used for this issue.

@eopb eopb 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 Dec 23, 2022
@eopb
Copy link
Contributor Author

eopb commented Dec 23, 2022

@rustbot claim

@eopb eopb changed the title misleading add dyn to derive macro suggestion misleading "add dyn keyword before derive macro" suggestion Dec 23, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 14, 2023
fix: misleading "add dyn keyword before derive macro" suggestion

Fixes rust-lang#106071
@bors bors closed this as completed in d7fcd01 Jan 15, 2023
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 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.

1 participant