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

Stable sort primitive #5809

Merged
merged 2 commits into from
Aug 5, 2020
Merged

Conversation

JarredAllen
Copy link
Contributor

changelog: Implements #5762

@rust-highfive
Copy link

r? @phansch

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 16, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Not a review; just some comments.

clippy_lints/src/stable_sort_primitive.rs Outdated Show resolved Hide resolved
clippy_lints/src/stable_sort_primitive.rs Outdated Show resolved Hide resolved
@phansch
Copy link
Member

phansch commented Jul 21, 2020

Sorry for the silence and thanks for your PR - I'll get back to reviewing by tomorrow =)

@JarredAllen
Copy link
Contributor Author

@phansch Is the review still coming?

@flip1995
Copy link
Member

ping from triage @phansch. This is still waiting on your review. If you are currently too busy, you can r? this to someone else.

@phansch
Copy link
Member

phansch commented Jul 29, 2020

Sorry again for the silence, got some IRL stuff to deal with that drains my energy, so I'm handing this off to someone else 💙

r? @Manishearth

@rust-highfive rust-highfive assigned Manishearth and unassigned phansch Jul 29, 2020
@@ -9,7 +9,6 @@ fn unnecessary_sort_by() {

let mut vec: Vec<isize> = vec![3, 6, 1, 2, 5];
// Forward examples
vec.sort_by(|a, b| a.cmp(b));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should keep this test until we implement unstable sort lint for sort_by (SortingKind::ByCmp)

// positive examples
let mut vec = vec![1, 3, 2];
vec.sort_unstable();
let mut vec = vec![false, false, true];
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a test for chars as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also test cases for types that deref to a slice of primitives.

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 believe Vec derefs to a slice, so I think the tests already have that last bit covered, unless I don't understand what you're getting at.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you are correct. My bad.

Copy link
Contributor

Choose a reason for hiding this comment

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

@JarredAllen Hey should we add test cases for list of tuples such as: vec![(2, 1), (1, 3), (3, 2)]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@krishna-veerareddy I added test cases for a list of tuples and also for one of arrays.


/// Returns true iff the given type is a primitive which we should lint
/// on.
fn is_primitive_type(ty: Ty<'_>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we extend this to include a list of static strings such as ["ab", "bc", "ab", "cd"]. This would qualify for an unstable sort, right?

Copy link
Member

Choose a reason for hiding this comment

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

That should be a Ref of a Slice of a Str

Can we rename this function is_recursively_primitive_type and stick it in utils somewhere?

@Manishearth
Copy link
Member

@krishna-veerareddy I'll let you review this PR since you've already started, let me know when you think it's ready!

@krishna-veerareddy
Copy link
Contributor

@Manishearth Hey this looks good to me. Can you please take a look when you have some time. Thanks!

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

Minor comments, also please squash the PR

/// The three "kinds" of sorts
enum SortingKind {
Vanilla,
/* The other kinds of lint are currently commented out because they
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 avoid using multiline comments and instead just use lots of //, it's pretty standard style in Rust or at least in this codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, cargo dev fmt seems to insist on changing those comments to be multiline ones.


/// Returns true iff the given type is a primitive which we should lint
/// on.
fn is_primitive_type(ty: Ty<'_>) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

That should be a Ref of a Slice of a Str

Can we rename this function is_recursively_primitive_type and stick it in utils somewhere?


/// Returns true iff the given expression is a slice of primitives or if
/// it is of some type that implements deref to such a slice
fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Can this also be in utils?

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 3, 2020

📌 Commit 25abd7a has been approved by Manishearth

@bors
Copy link
Collaborator

bors commented Aug 3, 2020

⌛ Testing commit 25abd7a with merge b04f3b1...

bors added a commit that referenced this pull request Aug 3, 2020
@bors
Copy link
Collaborator

bors commented Aug 3, 2020

💔 Test failed - checks-action_dev_test

@flip1995
Copy link
Member

flip1995 commented Aug 4, 2020

Needs a cargo dev fmt

@JarredAllen
Copy link
Contributor Author

@flip1995 The only changed caused by running cargo dev fmt is replacing some multiple-line \\ comments with multiple-line /* comments, which it was explicitly suggested that I do the opposite of. Should I go back to the way cargo dev fmt suggests?

@Manishearth
Copy link
Member

Yes please. I'm surprised it does that, but whatever 😄

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 5, 2020

📌 Commit 542740c has been approved by Manishearth

@bors
Copy link
Collaborator

bors commented Aug 5, 2020

⌛ Testing commit 542740c with merge 2d4c337...

@bors
Copy link
Collaborator

bors commented Aug 5, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing 2d4c337 to master...

@bors bors merged commit 2d4c337 into rust-lang:master Aug 5, 2020
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.

7 participants