mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
implicit_return: make it use a rustfix test
This commit is contained in:
parent
a2ab0698cc
commit
ee9e1af4ed
102
tests/ui/implicit_return.fixed
Normal file
102
tests/ui/implicit_return.fixed
Normal file
@ -0,0 +1,102 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::implicit_return)]
|
||||
#![allow(clippy::needless_return, unused)]
|
||||
|
||||
fn test_end_of_fn() -> bool {
|
||||
if true {
|
||||
// no error!
|
||||
return true;
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_bool)]
|
||||
fn test_if_block() -> bool {
|
||||
if true {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::match_bool)]
|
||||
#[rustfmt::skip]
|
||||
fn test_match(x: bool) -> bool {
|
||||
match x {
|
||||
true => return false,
|
||||
false => { return true },
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::match_bool, clippy::needless_return)]
|
||||
fn test_match_with_unreachable(x: bool) -> bool {
|
||||
match x {
|
||||
true => return false,
|
||||
false => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::never_loop)]
|
||||
fn test_loop() -> bool {
|
||||
loop {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::never_loop)]
|
||||
fn test_loop_with_block() -> bool {
|
||||
loop {
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::never_loop)]
|
||||
fn test_loop_with_nests() -> bool {
|
||||
loop {
|
||||
if true {
|
||||
return true;
|
||||
} else {
|
||||
let _ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::redundant_pattern_matching)]
|
||||
fn test_loop_with_if_let() -> bool {
|
||||
loop {
|
||||
if let Some(x) = Some(true) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_closure() {
|
||||
#[rustfmt::skip]
|
||||
let _ = || { return true };
|
||||
let _ = || return true;
|
||||
}
|
||||
|
||||
fn test_panic() -> bool {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn test_return_macro() -> String {
|
||||
return format!("test {}", "test")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = test_end_of_fn();
|
||||
let _ = test_if_block();
|
||||
let _ = test_match(true);
|
||||
let _ = test_match_with_unreachable(true);
|
||||
let _ = test_loop();
|
||||
let _ = test_loop_with_block();
|
||||
let _ = test_loop_with_nests();
|
||||
let _ = test_loop_with_if_let();
|
||||
test_closure();
|
||||
let _ = test_return_macro();
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
// run-rustfix
|
||||
|
||||
#![warn(clippy::implicit_return)]
|
||||
#![allow(clippy::needless_return, unused)]
|
||||
|
||||
fn test_end_of_fn() -> bool {
|
||||
if true {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:9:5
|
||||
--> $DIR/implicit_return.rs:12:5
|
||||
|
|
||||
LL | true
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
@ -7,61 +7,61 @@ LL | true
|
||||
= note: `-D clippy::implicit-return` implied by `-D warnings`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:15:9
|
||||
--> $DIR/implicit_return.rs:18:9
|
||||
|
|
||||
LL | true
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:17:9
|
||||
--> $DIR/implicit_return.rs:20:9
|
||||
|
|
||||
LL | false
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:25:17
|
||||
--> $DIR/implicit_return.rs:28:17
|
||||
|
|
||||
LL | true => false,
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:26:20
|
||||
--> $DIR/implicit_return.rs:29:20
|
||||
|
|
||||
LL | false => { true },
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:41:9
|
||||
--> $DIR/implicit_return.rs:44:9
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:49:13
|
||||
--> $DIR/implicit_return.rs:52:13
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:58:13
|
||||
--> $DIR/implicit_return.rs:61:13
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:76:18
|
||||
--> $DIR/implicit_return.rs:79:18
|
||||
|
|
||||
LL | let _ = || { true };
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:77:16
|
||||
--> $DIR/implicit_return.rs:80:16
|
||||
|
|
||||
LL | let _ = || true;
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing return statement
|
||||
--> $DIR/implicit_return.rs:85:5
|
||||
--> $DIR/implicit_return.rs:88:5
|
||||
|
|
||||
LL | format!("test {}", "test")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`
|
||||
|
Loading…
Reference in New Issue
Block a user