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

Reprise: new lint: Unintentional return of unit from closures expecting Ord #5737

Merged
merged 1 commit into from
Jul 14, 2020
Merged

Reprise: new lint: Unintentional return of unit from closures expecting Ord #5737

merged 1 commit into from
Jul 14, 2020

Conversation

Uriopass
Copy link

@Uriopass Uriopass commented Jun 22, 2020

This lint catches cases where the last statement of a closure expecting
an instance of Ord has a trailing semi-colon. It compiles since the
closure ends up return () which also implements Ord but causes
unexpected results in cases such as sort_by_key.

Fixes #5080

Reprise of #5348 where I addressed all the comments there

changelog: add lint [unit_return_expecting_ord]

@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 @Manishearth (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 Jun 22, 2020
@Uriopass
Copy link
Author

r? @flip1995 since he worked on the previous pr

@Uriopass
Copy link
Author

(Looks like the CI doesn't work but it seems unrelated to the changes ?)

@flip1995
Copy link
Member

Yes this is unrelated and will be fixed tomorrow (if no other unexpected breakage occurs). In regard of reviewing this: I will do that after we get Clippy working again in the Clippy repo and in the rustc repo. (hopefully in one or two days)

@flip1995
Copy link
Member

flip1995 commented Jun 22, 2020

What you can do in the meantime: Please squash the commit b8d55fc in your rebase commit, since the rebase commit reverts the former.

@Uriopass
Copy link
Author

Squashed

@Uriopass
Copy link
Author

Uriopass commented Jun 23, 2020

Looks like there are unrelated errors again, and a related one which I fixed.

EDIT: caused by rust-lang/rust#73578

@Uriopass
Copy link
Author

rebased

@Uriopass
Copy link
Author

Ok now I have actual test fails however I have no idea where it comes from :(

@Uriopass
Copy link
Author

(I'm sorry for wasting the CI a bit, I never contributed to clippy and can't run dogfood test since I'm on windows)

@Uriopass
Copy link
Author

🎉

@Uriopass Uriopass requested a review from flip1995 June 23, 2020 17:27
@Uriopass
Copy link
Author

Also addressing original author's remark:

If returning unit is intentional, then there is no way of specifying this without triggering needless_return lint

This is true for lots of lints, but they can be disabled selectively using #[allow(clippy::unintentional_unit_return)] no ?
I'm also not sure when lints should be in the nursery or not. Should this one be ?

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.

I have a feeling that there are FPs and FNs in the check if a closure returns (), see my comments below for details. LGTM overall though.

tests/ui/unintentional_unit_return.rs Outdated Show resolved Hide resolved
clippy_lints/src/unintentional_unit_return.rs Outdated Show resolved Hide resolved
@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 3, 2020
@Uriopass
Copy link
Author

Uriopass commented Jul 3, 2020

Added some tests and changed the way the lint looks. Now prints something like

error: This closure returns the unit type which also implements PartialOrd.
  --> $DIR/unintentional_unit_return.rs:20:30
   |
LL |     structs.is_sorted_by_key(|s| {
   |                              ^^^
   |
help: Probably caused by this trailing semicolon.
  --> $DIR/unintentional_unit_return.rs:21:24
   |
LL |         double(s.field);
   |                        ^

clippy_lints/src/unintentional_unit_return.rs Outdated Show resolved Hide resolved
clippy_lints/src/unintentional_unit_return.rs Outdated Show resolved Hide resolved
tests/ui/unintentional_unit_return.rs Outdated Show resolved Hide resolved
@Uriopass Uriopass requested a review from flip1995 July 3, 2020 16:55
@flip1995
Copy link
Member

flip1995 commented Jul 3, 2020

Can you squash some of the commits, please? After that, this should be good to go 🚀

@Uriopass
Copy link
Author

Uriopass commented Jul 3, 2020

Just, should this be in the nursery (as it is right now) ? Or what's the best category ? i would guess correctness (akin to unit_cmp) ?

/// twins.sort_by_key(|x| { x.1; });
/// ```
pub UNINTENTIONAL_UNIT_RETURN,
nursery,
Copy link
Member

Choose a reason for hiding this comment

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

I think we can move this to correctness since it should be finished now. Or do you know of any problems you encountered with this lint, while implementing/testing it?

Copy link
Author

Choose a reason for hiding this comment

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

Nope, I think it serves the exact purpose it was made for.

@Uriopass
Copy link
Author

Moved from nursery to correctness and rewritten to description to match current (updated) behavior

@flip1995
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Jul 13, 2020

📌 Commit 0f7cbf4 has been approved by flip1995

@flip1995 flip1995 added S-waiting-on-bors Status: The marked PR was approved and is only waiting bors and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jul 13, 2020
@bors
Copy link
Contributor

bors commented Jul 13, 2020

⌛ Testing commit 0f7cbf4 with merge 88388eb...

bors added a commit that referenced this pull request Jul 13, 2020
Reprise: new lint: Unintentional return of unit from closures expecting Ord

This lint catches cases where the last statement of a closure expecting
an instance of Ord has a trailing semi-colon. It compiles since the
closure ends up return () which also implements Ord but causes
unexpected results in cases such as sort_by_key.

Fixes #5080

Reprise of #5348 where I addressed all the comments there
@bors
Copy link
Contributor

bors commented Jul 13, 2020

💔 Test failed - checks-action_test

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.

I took another look at the lint name

clippy_lints/src/unintentional_unit_return.rs Outdated Show resolved Hide resolved
This lint catches cases where the last statement of a closure expecting
an instance of Ord has a trailing semi-colon. It compiles since the
closure ends up return () which also implements Ord but causes
unexpected results in cases such as sort_by_key.

Fixes #5080

reprise: rebase, update and address all concerns
@Uriopass
Copy link
Author

Uriopass commented Jul 14, 2020

Renamed, rebased and rustuped

@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Jul 14, 2020

📌 Commit 1267909 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jul 14, 2020

⌛ Testing commit 1267909 with merge 97d7a8b...

@bors
Copy link
Contributor

bors commented Jul 14, 2020

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

@bors bors merged commit 97d7a8b into rust-lang:master Jul 14, 2020
@Uriopass
Copy link
Author

Nice !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: The marked PR was approved and is only waiting bors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint: Returning unit type when expecting Ord
6 participants