Skip to content

E0277 for #[derive(_)]-able trait on local type should have structured suggestion #95099

Closed
@estebank

Description

@estebank

When encountering code that requires a deriveable trait on a type that doesn't have it, we currently emit an E0277 error and when possible point at the trait bound that introduced the obligation:

error[E0277]: can't compare `S` with `S`
 --> src/main.rs:3:9
  |
3 |     foo(S);
  |     --- ^ no implementation for `S == S`
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `PartialEq` is not implemented for `S`
note: required by a bound in `foo`
 --> src/main.rs:6:11
  |
6 | fn foo<T: PartialEq>(_: T) {}
  |           ^^^^^^^^^ required by this bound in `foo`

When the bound applies on a local type, we should suggest

help: consider annotating `S` with `#[derive(PartialEq)]`
  |
1 | #[derive(PartialEq)]
  |

like we do for E0369.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-lowLow priorityT-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