-
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
Fix the reversed suggestion message of stable_sort_primitive
.
#6611
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (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. |
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.
You will have to run cargo uitest && cargo dev bless
I think everything should be good now. It is my first time to do a PR, so if there is still something need to be corrected, please just tell me. |
Hmm the error seems right to me and looks reversed after this change. The reason for the suggestion should probably be more explicit though. You could add a sentence to the error:
|
Oh, I must have mistaken "used" to "use", which reverses the meaning of the whole sentence. I think we can avoid mentioning the unstable sort in the first sentence, so it clearly points to the problem of the code, and the following "help" will tell the user the right method to use. Also, I add an explicit reason just as @camsteffen suggests. Now the message looks like this:
|
@@ -112,8 +112,8 @@ impl LateLintPass<'_> for StableSortPrimitive { | |||
STABLE_SORT_PRIMITIVE, | |||
expr.span, | |||
format!( | |||
"used {} instead of {} to sort primitive type `{}`", | |||
detection.method.unstable_name(), | |||
"used `{}` on primitive type `{}`. An unstable sort would perform faster \ |
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 would use span_lint_and_then
here and split up the "used `sort`...
" message and the explaining message:
span_lint_and_then(
cx,
STABLE_SORT_PRIMITIVE,
expr.span,
format!(
"used `{}` on primitive type `{}`",
detection.method.stable_name(),
detection.slice_type,
),
|diag| {
diag.span_suggestion(
expr.span,
"try",
format!(
"{}.{}({})",
detection.slice_name,
detection.method.unstable_name(),
detection.method_args,
),
Applicability::MachineApplicable,
);
diag.note("an unstable sort would perform faster without any observable difference for this data 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 have updated the code using span_lint_and_then
.
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.
Thanks! Please squash your commits and I'll merge this 👍
Commits squashed. Thank you! |
@bors r+ Thanks! Looking forward to your next contribution! 🙂 |
📌 Commit e42208f has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Now Clippy emits
stable_sort_primitive
warning as follows:I think the position of
sort
andsort_unstable
in the first line should be reversed.changelog: Fix the reversed suggestion message of
stable_sort_primitive
.