-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New lint: Use Reverse with sort_by_key #5623
Conversation
Param { pat: Pat { kind: PatKind::Binding(_, _, b_ident, _), .. }, .. } | ||
] = &closure_body.params; | ||
if let ExprKind::MethodCall(method_path, _, [ref b_expr, ref a_expr]) = &closure_body.value.kind; | ||
if method_path.ident.name.to_ident_string() == "cmp"; |
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.
Or partial_cmp
?
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.
If I'm not mistaken, the sort_by_key method requires a function which returns something implementing Ord
, whereas partial_cmp
would only guarantee that the type implements PartialOrd
. It would be possible to check if they're calling partial_cmp
and the underlying type implements Ord
, but I'm not sure if it would be worth it. How often do people use partial_cmp
when they can use cmp
?
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.
Indeed. Good point.
How often do people use
partial_cmp
when they can usecmp
?
I dunno. It's nice to have but I can understand skipping it.
It just occurred to me that we're skipping over a simpler lint. Could this be easily generalized to also cover cases of |
That generalization would be pretty easy to do. I should be able to make that happen. |
I've added that generalization, and I also made it detect that |
Re-opening to trigger a new build |
Sorry to suggest another rename, but it may be good since the lint now covers |
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.
Overall this looks good to me, thanks!
Regarding the lint name I would probably opt for unnecessary_sort_by
as @camsteffen suggests
701a214
to
9a5baed
Compare
I think I just addressed those suggestions @phansch suggested |
Ok, I missed re-running update_lints after renaming the lint, but now it should be good. |
@bors r+ thanks! |
📌 Commit b89880a has been approved by |
New lint: Use Reverse with sort_by_key Implements #5578
💔 Test failed - checks-action_test |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Implements #5578
changelog: New lint: [
unnecessary_sort_by
]