2

Github Fix false positive on `semicolon_if_nothing_returned` by 1c3t3a · Pull Re...

 2 years ago
source link: https://github.com/rust-lang/rust-clippy/pull/7326
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Contributor

1c3t3a commented 14 days ago

edited

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK