Skip to content

Provide better error reporting for unimplemented traits #19950

Closed
@flaper87

Description

@flaper87
struct NoCopy;

enum Test {
    MyVariant(NoCopy)
}

impl Copy for Test {}

fn main() {}

Compiling the above code generates the following error:

phantom /tmp $ rustc test.rs
test.rs:7:1: 7:22 error: the trait `Copy` may not be implemented for this type; variant `MyVariant` does not implement `Copy`
test.rs:7 impl Copy for Test {}
          ^~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

The error mentions that MyVariant doesn't implement Copy without pointing to the right type in the constructor that is actually missing the implementation NoCopy.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions