Skip to content
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

Merged
merged 1 commit into from
Jan 21, 2021
Merged

Fix the reversed suggestion message of stable_sort_primitive. #6611

merged 1 commit into from
Jan 21, 2021

Conversation

pastchick3
Copy link
Contributor

Now Clippy emits stable_sort_primitive warning as follows:

warning: used sort instead of sort_unstable to sort primitive type `usize`
  --> src\asm.rs:41:13
   |
41 |             self.successors.sort();
   |             ^^^^^^^^^^^^^^^^^^^^^^ help: try: `self.successors.sort_unstable()`
   |
   = note: `#[warn(clippy::stable_sort_primitive)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive

I think the position of sort and sort_unstable in the first line should be reversed.

changelog: Fix the reversed suggestion message of stable_sort_primitive.

@rust-highfive
Copy link

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 20, 2021
@pastchick3 pastchick3 marked this pull request as draft January 20, 2021 13:13
Copy link
Member

@flip1995 flip1995 left a 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

@pastchick3 pastchick3 marked this pull request as ready for review January 20, 2021 14:27
@pastchick3
Copy link
Contributor Author

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.

@camsteffen
Copy link
Contributor

I think the position of sort and sort_unstable in the first line should be reversed.

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:

An unstable sort would perform faster without any observable difference for this data type.

@pastchick3
Copy link
Contributor Author

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:

error: used `sort` on primitive type `i32`. An unstable sort would perform faster without any observable difference for this data type.
  --> $DIR/stable_sort_primitive.rs:7:5
   |
LL |     vec.sort();
   |     ^^^^^^^^^^ help: try: `vec.sort_unstable()`
   |
   = note: `-D clippy::stable-sort-primitive` implied by `-D warnings`

@@ -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 \
Copy link
Member

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");
    }
)

Copy link
Contributor Author

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.

Copy link
Member

@flip1995 flip1995 left a 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 👍

@pastchick3
Copy link
Contributor Author

Commits squashed. Thank you!

@flip1995
Copy link
Member

@bors r+

Thanks! Looking forward to your next contribution! 🙂

@bors
Copy link
Contributor

bors commented Jan 21, 2021

📌 Commit e42208f has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jan 21, 2021

⌛ Testing commit e42208f with merge 16d13a5...

@bors
Copy link
Contributor

bors commented Jan 21, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 16d13a5 to master...

@bors bors merged commit 16d13a5 into rust-lang:master Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants