Skip to content
7 changes: 7 additions & 0 deletions compiler/rustc_typeck/src/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,13 @@ fn suggest_impl_missing(err: &mut DiagnosticBuilder<'_>, ty: Ty<'_>, missing_tra
"an implementation of `{}` might be missing for `{}`",
missing_trait, ty
));
// This checks if the missing trait is PartialEq to suggest adding a derive
if missing_trait.ends_with("PartialEq") {
err.note(&format!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use span_suggestion, as this is a suggestion. You should move this to somewhere else, so you can look up the span of the original definition for the type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that a span suggestion is better. A note at the end is clearer. Why do you want a span_suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you want to suggest adding a derive to the type being compared here. So you use the span of the original definition and add a #[derive(PartialEq)] on top of it, or add PartialEq to the existing derive.

"add `#[derive(PartialEq)]` or manually implement `PartialEq` for `{}`",
ty
));
}
}
}
}
Expand Down