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

Deriving Clone and Copy twice generates bad diagnostics #131083

Open
cyrgani opened this issue Oct 1, 2024 · 0 comments
Open

Deriving Clone and Copy twice generates bad diagnostics #131083

cyrgani opened this issue Oct 1, 2024 · 0 comments
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

@cyrgani
Copy link
Contributor

cyrgani commented Oct 1, 2024

Code

#[derive(Clone, Copy)]
#[derive(Clone, Copy)]
enum E {}

Current output

error[E0119]: conflicting implementations of trait `Clone` for type `E`
 --> src/lib.rs:2:10
  |
1 | #[derive(Clone, Copy)]
  |          ----- first implementation here
2 | #[derive(Clone, Copy)]
  |          ^^^^^ conflicting implementation for `E`
  |
  = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0119]: conflicting implementations of trait `Copy` for type `E`
 --> src/lib.rs:2:17
  |
1 | #[derive(Clone, Copy)]
  |                 ---- first implementation here
2 | #[derive(Clone, Copy)]
  |                 ^^^^ conflicting implementation for `E`
  |
  = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0507]: cannot move out of `*self` which is behind a shared reference
 --> src/lib.rs:2:10
  |
2 | #[derive(Clone, Copy)]
  |          ^^^^^ move occurs because `*self` has type `E`, which does not implement the `Copy` trait
  |
note: if `E` implemented `Clone`, you could clone the value
 --> src/lib.rs:3:1
  |
2 | #[derive(Clone, Copy)]
  |          ----- you could clone this value
3 | enum E {}
  | ^^^^^^ consider implementing `Clone` for this type
  = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0507]: cannot move out of `*self` which is behind a shared reference
 --> src/lib.rs:1:10
  |
1 | #[derive(Clone, Copy)]
  |          ^^^^^ move occurs because `*self` has type `E`, which does not implement the `Copy` trait
  |
note: if `E` implemented `Clone`, you could clone the value
 --> src/lib.rs:3:1
  |
1 | #[derive(Clone, Copy)]
  |          ----- you could clone this value
2 | #[derive(Clone, Copy)]
3 | enum E {}
  | ^^^^^^ consider implementing `Clone` for this type
  = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

Desired output

error[E0119]: conflicting implementations of trait `Clone` for type `E`
 --> src/lib.rs:2:10
  |
1 | #[derive(Clone, Copy)]
  |          ----- first implementation here
2 | #[derive(Clone, Copy)]
  |          ^^^^^ conflicting implementation for `E`
  |
  = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0119]: conflicting implementations of trait `Copy` for type `E`
 --> src/lib.rs:2:17
  |
1 | #[derive(Clone, Copy)]
  |                 ---- first implementation here
2 | #[derive(Clone, Copy)]
  |                 ^^^^ conflicting implementation for `E`
  |
  = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

Rationale and extra context

First encountered this with a macro that automatically derived Clone and Copy. The later two errors are pointing to internal implementation details and have wrong spans; they should be removed. They also suggest "consider implementing Clone for this type", which is nonsense.

Other cases

No response

Rust Version

1.83.0 nightly on playground

Anything else?

No response

@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 Oct 1, 2024
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

No branches or pull requests

1 participant