rust/tests/ui/implicit_return.fixed
2020-04-23 16:30:06 -07:00

101 lines
1.7 KiB
Rust

// 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
}
}
#[rustfmt::skip]
fn test_match(x: bool) -> bool {
match x {
true => return false,
false => { return true },
}
}
#[allow(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();
}