-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fixed #85845: Added a note in E0369 if the missing trait is PartialEq #85929
Conversation
…rive. This is my first contribution so tell me if some guidelines aren't respected.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
You should add a UI test for this, see this |
@@ -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!( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for how long its taken me to get to this review, this is a good improvement, and I've made a suggestion on how the condition you've added could be more robust.
@ccgauche Ping from triage, would you mind addressing the review comments above? Thanks! |
I'm in vacations currently. I'll address that next week.
Le dim. 4 juil. 2021 à 06:41, Charles Lew ***@***.***> a
écrit :
… @ccgauche <https://github.com/ccgauche> Ping from triage, would you mind
addressing the review comments above? Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#85929 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD63CQ4435SG3QBSFMPIKZDTV7RA3ANCNFSM456NU7AQ>
.
|
@ccgauche Ping from triage, any updates here? |
Yep sorry it is a little more complicated on my side than expected. I'll see what I can do in the next few days. |
- Made the check stricter. **Note: I've checked and there is no other trait that can be possibly passed than std ones. (BinOps) so there is no need for a `can_derive` or something similar. Furthermore, this mean we can't pass another thing than a str.**
This comment has been minimized.
This comment has been minimized.
I also fixed the issue for |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@ccgauche Do you still want to work on this, or is it fine if I take this on myself? |
You can work on it if you want! I'm currently in vacations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still like to see the changes suggested in #85929 (comment) be made, I'd rather we didn't add string comparions if it can be avoided.
Yeah, I'm sorry I don't have time to implement this. Maybe someone else can try? |
@davidtwco Can you check my changes and confirm that's what you want? This fix replaces all strings with an enum that has defined states so we are sure we don't encounter problems with string checks. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, left a few small nits but r=me after that.
@@ -1124,6 +1167,13 @@ impl UnOp { | |||
Self::Neg => "-", | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} | |
nit: newline
@@ -951,14 +938,56 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool | |||
} | |||
} | |||
|
|||
enum STDImplementationMissing { | |||
Unop(hir::UnOp), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unop(hir::UnOp), | |
UnOp(hir::UnOp), |
nit: consistency
@@ -951,14 +938,56 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool | |||
} | |||
} | |||
|
|||
enum STDImplementationMissing { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum STDImplementationMissing { | |
enum StdImplementationMissing { |
nit: capitalisation
☔ The latest upstream changes (presumably #87280) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: @ccgauche can you please resolve the merge conflict? |
Ping again from triage: @ccgauche can you please resolve the merge conflict? |
This PR fixes #85845.
A new note has been added if the missing trait is PartialEq:
I'm not sure the ends_with is the best way but I want this change to affect
core
,std
or custom libs. So using a full strict path isn't possible.This is my first contribution so tell me if some guidelines aren't respected.