Skip to content

Fix false positive on semicolon_if_nothing_returned #7326

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

Merged
merged 4 commits into from
Jun 9, 2021

Conversation

1c3t3a
Copy link
Member

@1c3t3a 1c3t3a commented Jun 5, 2021

Currently the semicolon_if_nothing_returned lint fires in unwanted situations where a block only spans one line. An example of this was given in #7324. This code:

use std::mem::MaybeUninit;
use std::ptr;

fn main() {
    let mut s = MaybeUninit::<String>::uninit();
    let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
}

yields the following clippy error:

error: consider adding a `;` to the last statement for consistent formatting
 --> src/main.rs:6:26
  |
6 |     let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
  |
  = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned

I updated the lint to check if the statement is inside an unsafe block, a closure or a normal block and if the block only spans one line, in that case the lint is not emitted.

This closes #7324.

changelog: enhanced semicolon if nothing returned according to #7324.

@rust-highfive
Copy link

r? @flip1995

(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 Jun 5, 2021
@flip1995
Copy link
Member

flip1995 commented Jun 5, 2021

Please rebase on master. You have a commit in this PR that is already on master.

@1c3t3a 1c3t3a force-pushed the 1c3t3a-issue-7324 branch from 611aee9 to 790888d Compare June 5, 2021 16:55
@1c3t3a
Copy link
Member Author

1c3t3a commented Jun 5, 2021

Sorry, just rebased moments before the PR, guess it was bad timing...

@1c3t3a 1c3t3a changed the title 1c3t3a issue 7324 Fixe false positive on semicolon_if_nothing_returned Jun 5, 2021
@1c3t3a 1c3t3a changed the title Fixe false positive on semicolon_if_nothing_returned Fix false positive on semicolon_if_nothing_returned Jun 5, 2021
@1c3t3a
Copy link
Member Author

1c3t3a commented Jun 6, 2021

Looking at #7322, this PR would favor the unsafe { f(x) }; style. But as described in the issue, it might be better to have this in a separate, configurable lint.

@1c3t3a 1c3t3a force-pushed the 1c3t3a-issue-7324 branch from 337ab40 to 977229f Compare June 7, 2021 19:45
@1c3t3a
Copy link
Member Author

1c3t3a commented Jun 7, 2021

Alright, I added the changes discussed on Zulip, this PR is now ready for review @flip1995!

@1c3t3a 1c3t3a force-pushed the 1c3t3a-issue-7324 branch from 977229f to 6bf8303 Compare June 7, 2021 20:06
@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 Jun 8, 2021
@1c3t3a 1c3t3a requested a review from flip1995 June 9, 2021 07:39
@1c3t3a 1c3t3a force-pushed the 1c3t3a-issue-7324 branch from 6d71ba7 to 5ec80f3 Compare June 9, 2021 07:43
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!

@flip1995
Copy link
Member

flip1995 commented Jun 9, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Jun 9, 2021

📌 Commit 5ec80f3 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jun 9, 2021

⌛ Testing commit 5ec80f3 with merge dd02468...

@bors
Copy link
Contributor

bors commented Jun 9, 2021

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

@bors bors merged commit dd02468 into rust-lang:master Jun 9, 2021
@1c3t3a
Copy link
Member Author

1c3t3a commented Jun 9, 2021

Looking at #7322, this PR would favor the unsafe { f(x) }; style. But as described in the issue, it might be better to have this in a separate, configurable lint.

What do you think about that @flip1995? Same lint or a new one?

@flip1995
Copy link
Member

flip1995 commented Jun 9, 2021

That should be a new pedantic lint.

toku-sa-n added a commit to toku-sa-n/ramen that referenced this pull request Jun 16, 2021
rust-lang/rust-clippy#7326 does not seem to be
included in the latest Clippy binary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

semicolon_if_nothing_returned false positive inside unsafe block
4 participants