mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
needless_return: add allow()s to test, make rustfixable
This commit is contained in:
parent
980650eec2
commit
a9a3350455
3 changed files with 94 additions and 12 deletions
78
tests/ui/needless_return.fixed
Normal file
78
tests/ui/needless_return.fixed
Normal file
|
@ -0,0 +1,78 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused, clippy::needless_bool, clippy::match_bool)]
|
||||
#![allow(clippy::if_same_then_else, clippy::single_match)]
|
||||
#![warn(clippy::needless_return)]
|
||||
|
||||
macro_rules! the_answer {
|
||||
() => {
|
||||
42
|
||||
};
|
||||
}
|
||||
|
||||
fn test_end_of_fn() -> bool {
|
||||
if true {
|
||||
// no error!
|
||||
return true;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn test_no_semicolon() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn test_if_block() -> bool {
|
||||
if true {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn test_match(x: bool) -> bool {
|
||||
match x {
|
||||
true => false,
|
||||
false => {
|
||||
true
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn test_closure() {
|
||||
let _ = || {
|
||||
true
|
||||
};
|
||||
let _ = || true;
|
||||
}
|
||||
|
||||
fn test_macro_call() -> i32 {
|
||||
return the_answer!();
|
||||
}
|
||||
|
||||
fn test_void_fun() {
|
||||
|
||||
}
|
||||
|
||||
fn test_void_if_fun(b: bool) {
|
||||
if b {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fn test_void_match(x: u32) {
|
||||
match x {
|
||||
0 => (),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = test_end_of_fn();
|
||||
let _ = test_no_semicolon();
|
||||
let _ = test_if_block();
|
||||
let _ = test_match(true);
|
||||
test_closure();
|
||||
}
|
|
@ -1,3 +1,7 @@
|
|||
// run-rustfix
|
||||
|
||||
#![allow(unused, clippy::needless_bool, clippy::match_bool)]
|
||||
#![allow(clippy::if_same_then_else, clippy::single_match)]
|
||||
#![warn(clippy::needless_return)]
|
||||
|
||||
macro_rules! the_answer {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:14:5
|
||||
--> $DIR/needless_return.rs:18:5
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
@ -7,67 +7,67 @@ LL | return true;
|
|||
= note: `-D clippy::needless-return` implied by `-D warnings`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:18:5
|
||||
--> $DIR/needless_return.rs:22:5
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:23:9
|
||||
--> $DIR/needless_return.rs:27:9
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:25:9
|
||||
--> $DIR/needless_return.rs:29:9
|
||||
|
|
||||
LL | return false;
|
||||
| ^^^^^^^^^^^^^ help: remove `return`: `false`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:31:17
|
||||
--> $DIR/needless_return.rs:35:17
|
||||
|
|
||||
LL | true => return false,
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `false`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:33:13
|
||||
--> $DIR/needless_return.rs:37:13
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:40:9
|
||||
--> $DIR/needless_return.rs:44:9
|
||||
|
|
||||
LL | return true;
|
||||
| ^^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:42:16
|
||||
--> $DIR/needless_return.rs:46:16
|
||||
|
|
||||
LL | let _ = || return true;
|
||||
| ^^^^^^^^^^^ help: remove `return`: `true`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:50:5
|
||||
--> $DIR/needless_return.rs:54:5
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^^ help: remove `return`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:55:9
|
||||
--> $DIR/needless_return.rs:59:9
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^^ help: remove `return`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:57:9
|
||||
--> $DIR/needless_return.rs:61:9
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^^ help: remove `return`
|
||||
|
||||
error: unneeded return statement
|
||||
--> $DIR/needless_return.rs:64:14
|
||||
--> $DIR/needless_return.rs:68:14
|
||||
|
|
||||
LL | _ => return,
|
||||
| ^^^^^^ help: replace `return` with an empty block: `{}`
|
||||
|
|
Loading…
Reference in a new issue