rust/tests/ui/implicit_return.rs

90 lines
1.5 KiB
Rust
Raw Normal View History

#![warn(clippy::implicit_return)]
2018-12-05 08:59:09 +08:00
fn test_end_of_fn() -> bool {
if true {
// no error!
return true;
}
true
}
#[allow(clippy::needless_bool)]
fn test_if_block() -> bool {
if true {
true
} else {
false
}
}
#[allow(clippy::match_bool)]
#[rustfmt::skip]
2018-12-05 08:59:09 +08:00
fn test_match(x: bool) -> bool {
match x {
true => false,
false => { true },
2018-12-05 08:59:09 +08:00
}
}
2019-01-20 20:45:22 +08:00
#[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 {
break true;
}
}
2018-12-16 22:42:02 +08: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-17 05:20:05 +08:00
break true;
} else {
2018-12-17 05:20:05 +08:00
let _ = true;
2018-12-16 22:42:02 +08:00
}
}
}
2019-01-20 20:45:22 +08: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 08:59:09 +08:00
fn test_closure() {
#[rustfmt::skip]
let _ = || { true };
2018-12-05 08:59:09 +08:00
let _ = || true;
}
fn main() {
let _ = test_end_of_fn();
let _ = test_if_block();
let _ = test_match(true);
2019-01-20 20:45:22 +08:00
let _ = test_match_with_unreachable(true);
let _ = test_loop();
2018-12-16 22:42:02 +08:00
let _ = test_loop_with_block();
let _ = test_loop_with_nests();
2019-01-20 20:45:22 +08:00
let _ = test_loop_with_if_let();
2018-12-05 08:59:09 +08:00
test_closure();
}