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

add [assertions_on_result_states] lint #9225

Merged
merged 1 commit into from
Jul 25, 2022
Merged

Conversation

tabokie
Copy link
Contributor

@tabokie tabokie commented Jul 22, 2022

Close #9162

changelog: add [assertions_on_result_states] lint

Signed-off-by: tabokie [email protected]

@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 @xFrednet (or someone else) soon.

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 Jul 22, 2022
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

Two small things, and then one suggested extension which should be easy enough to add.

Can you also add a check for is_err with the suggestion to use unwrap_err to the same lint. Could be named something like assert_result_state.

clippy_lints/src/assert_ok.rs Outdated Show resolved Hide resolved
clippy_lints/src/assert_ok.rs Outdated Show resolved Hide resolved
@tabokie
Copy link
Contributor Author

tabokie commented Jul 22, 2022

@Jarcho Thanks for the review.

Can you also add a check for is_err with the suggestion to use unwrap_err to the same lint.

I have doubts about this. unwrap is more favorable in the error message part, but unwrap_err is pretty much equivalent to is_err. So I think we shouldn't enforce it, at least not in the same level as is_ok.

Forget it, I was being silly.

@tabokie tabokie changed the title add [assert_ok] lint add [assertions_on_result_states] lint Jul 22, 2022
@tabokie tabokie requested a review from Jarcho July 22, 2022 16:03
clippy_lints/src/assertions_on_result_states.rs Outdated Show resolved Hide resolved
clippy_lints/src/assertions_on_result_states.rs Outdated Show resolved Hide resolved
clippy_lints/src/assertions_on_result_states.rs Outdated Show resolved Hide resolved
@Jarcho
Copy link
Contributor

Jarcho commented Jul 23, 2022

There's one more issue to handle after the previous smaller things. This change does result in a behaviour change. Namely unwrap consumes it's argument whereas is_ok does not. If you restrict this to Result types which implement Copy (use `clippy_utils::ty::is_copy) that would be fine.

If you want to go further you can check if the value is both movable, and not used afterwards. I wouldn't recommend this for the current PR as it's a fair amount of extra work.

@tabokie tabokie requested a review from Jarcho July 24, 2022 04:18
clippy_lints/src/assertions_on_result_states.rs Outdated Show resolved Hide resolved
clippy_lints/src/assertions_on_result_states.rs Outdated Show resolved Hide resolved
@tabokie tabokie requested a review from Jarcho July 25, 2022 03:12
@tabokie tabokie requested a review from Jarcho July 25, 2022 11:01
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

Everything looks good. You can just squash it down and we're good to merge.

@tabokie
Copy link
Contributor Author

tabokie commented Jul 25, 2022

@Jarcho It's done. Thanks.

@Jarcho
Copy link
Contributor

Jarcho commented Jul 25, 2022

Thank you.

@bors r+

@bors
Copy link
Contributor

bors commented Jul 25, 2022

📌 Commit 8454602 has been approved by Jarcho

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 25, 2022

⌛ Testing commit 8454602 with merge 1cce047...

@bors
Copy link
Contributor

bors commented Jul 25, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Jarcho
Pushing 1cce047 to master...

@bors bors merged commit 1cce047 into rust-lang:master Jul 25, 2022
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.

Deny assert!(res.is_ok()) in tests
5 participants