Skip to content

diagnostics: Duplicate derive clone suggestion #91492

Closed
@eopb

Description

@eopb

Given the following code: Playground

pub struct Foo;
fn fun(foo: &mut Vec<Foo>, bar: &[Foo]) {
    foo.extend_from_slice(bar);
}

The current output is:

error[E0599]: the method `extend_from_slice` exists for mutable reference `&mut Vec<Foo>`, but its trait bounds were not satisfied
 --> src/lib.rs:3:9
  |
1 | pub struct Foo;
  | ---------------------- doesn't satisfy `Foo: Clone`
2 | fn fun(foo: &mut Vec<Foo>, bar: &[Foo]) {
3 |     foo.extend_from_slice(bar);
  |         ^^^^^^^^^^^^^^^^^
  |
  = note: the following trait bounds were not satisfied:
          `Foo: Clone`
help: consider annotating `Foo` with `#[derive(Clone, Clone)]`
  |
1 | #[derive(Clone, Clone)]
  |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error

Ideally the output should look like:

error[E0599]: the method `extend_from_slice` exists for mutable reference `&mut Vec<Foo>`, but its trait bounds were not satisfied
 --> src/lib.rs:3:9
  |
1 | pub struct Foo;
  | ---------------------- doesn't satisfy `Foo: Clone`
2 | fn fun(foo: &mut Vec<Foo>, bar: &[Foo]) {
3 |     foo.extend_from_slice(bar);
  |         ^^^^^^^^^^^^^^^^^
  |
  = note: the following trait bounds were not satisfied:
          `Foo: Clone`
help: consider annotating `Foo` with `#[derive(Clone)]`
  |
1 | #[derive(Clone)]
  |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.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