Auto merge of #6681 - 1c3t3a:1c3t3a-issue-6467, r=xFrednet,flip1995,phansch

Adds a new lint that checks if there is a semicolon on the last block statement if it returns nothing

changelog: Added a new lint: `SEMICOLON_IF_NOTHING_RETURNED`
fixes #6467
Adds the `SEMICOLON_IF_NOTHING_RETURNED` lint and therefore closes #6467.
This commit is contained in:
bors 2021-02-07 08:53:52 +00:00
commit 001185d863
5 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,55 @@
#![warn(clippy::semicolon_if_nothing_returned)]
#![feature(label_break_value)]
fn get_unit() {}
// the functions below trigger the lint
fn main() {
println!("Hello")
}
fn hello() {
get_unit()
}
fn basic101(x: i32) {
let y: i32;
y = x + 1
}
// this is fine
fn print_sum(a: i32, b: i32) {
println!("{}", a + b);
assert_eq!(true, false);
}
fn foo(x: i32) {
let y: i32;
if x < 1 {
y = 4;
} else {
y = 5;
}
}
fn bar(x: i32) {
let y: i32;
match x {
1 => y = 4,
_ => y = 32,
}
}
fn foobar(x: i32) {
let y: i32;
'label: {
y = x + 1;
}
}
fn loop_test(x: i32) {
let y: i32;
for &ext in &["stdout", "stderr", "fixed"] {
println!("{}", ext);
}
}

View file

@ -0,0 +1,22 @@
error: consider adding a `;` to the last statement for consistent formatting
--> $DIR/semicolon_if_nothing_returned.rs:8:5
|
LL | println!("Hello")
| ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");`
|
= note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings`
error: consider adding a `;` to the last statement for consistent formatting
--> $DIR/semicolon_if_nothing_returned.rs:12:5
|
LL | get_unit()
| ^^^^^^^^^^ help: add a `;` here: `get_unit();`
error: consider adding a `;` to the last statement for consistent formatting
--> $DIR/semicolon_if_nothing_returned.rs:17:5
|
LL | y = x + 1
| ^^^^^^^^^ help: add a `;` here: `y = x + 1;`
error: aborting due to 3 previous errors