2019-09-20 09:07:13 +02:00
|
|
|
// run-rustfix
|
|
|
|
|
2018-12-05 14:39:09 +01:00
|
|
|
#![warn(clippy::implicit_return)]
|
2019-09-20 09:07:13 +02:00
|
|
|
#![allow(clippy::needless_return, unused)]
|
2018-12-05 01:59:09 +01:00
|
|
|
|
|
|
|
fn test_end_of_fn() -> bool {
|
|
|
|
if true {
|
|
|
|
// no error!
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-15 16:02:50 +02:00
|
|
|
|
2018-12-05 01:59:09 +01:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::needless_bool)]
|
|
|
|
fn test_if_block() -> bool {
|
|
|
|
if true {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::match_bool)]
|
2018-12-11 00:59:59 +01:00
|
|
|
#[rustfmt::skip]
|
2018-12-05 01:59:09 +01:00
|
|
|
fn test_match(x: bool) -> bool {
|
|
|
|
match x {
|
|
|
|
true => false,
|
2018-12-11 00:59:59 +01:00
|
|
|
false => { true },
|
2018-12-05 01:59:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 13:45:22 +01:00
|
|
|
#[allow(clippy::match_bool, clippy::needless_return)]
|
|
|
|
fn test_match_with_unreachable(x: bool) -> bool {
|
|
|
|
match x {
|
|
|
|
true => return false,
|
|
|
|
false => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 14:39:09 +01:00
|
|
|
#[allow(clippy::never_loop)]
|
|
|
|
fn test_loop() -> bool {
|
|
|
|
loop {
|
|
|
|
break true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:42:02 +01:00
|
|
|
#[allow(clippy::never_loop)]
|
|
|
|
fn test_loop_with_block() -> bool {
|
|
|
|
loop {
|
|
|
|
{
|
|
|
|
break true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::never_loop)]
|
|
|
|
fn test_loop_with_nests() -> bool {
|
|
|
|
loop {
|
|
|
|
if true {
|
2018-12-16 22:20:05 +01:00
|
|
|
break true;
|
2018-12-27 16:17:45 +01:00
|
|
|
} else {
|
2018-12-16 22:20:05 +01:00
|
|
|
let _ = true;
|
2018-12-16 15:42:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 13:45:22 +01:00
|
|
|
#[allow(clippy::redundant_pattern_matching)]
|
|
|
|
fn test_loop_with_if_let() -> bool {
|
|
|
|
loop {
|
|
|
|
if let Some(x) = Some(true) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:59:09 +01:00
|
|
|
fn test_closure() {
|
2018-12-11 00:59:59 +01:00
|
|
|
#[rustfmt::skip]
|
|
|
|
let _ = || { true };
|
2018-12-05 01:59:09 +01:00
|
|
|
let _ = || true;
|
|
|
|
}
|
|
|
|
|
2019-07-15 16:02:50 +02:00
|
|
|
fn test_panic() -> bool {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_return_macro() -> String {
|
|
|
|
format!("test {}", "test")
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:59:09 +01:00
|
|
|
fn main() {
|
|
|
|
let _ = test_end_of_fn();
|
|
|
|
let _ = test_if_block();
|
|
|
|
let _ = test_match(true);
|
2019-01-20 13:45:22 +01:00
|
|
|
let _ = test_match_with_unreachable(true);
|
2018-12-05 14:39:09 +01:00
|
|
|
let _ = test_loop();
|
2018-12-16 15:42:02 +01:00
|
|
|
let _ = test_loop_with_block();
|
|
|
|
let _ = test_loop_with_nests();
|
2019-01-20 13:45:22 +01:00
|
|
|
let _ = test_loop_with_if_let();
|
2018-12-05 01:59:09 +01:00
|
|
|
test_closure();
|
2019-07-15 16:02:50 +02:00
|
|
|
let _ = test_return_macro();
|
2018-12-05 01:59:09 +01:00
|
|
|
}
|