rust/tests/ui/implicit_return.fixed
Jason Newcomb 22f8c13cf5
Improve implicit_return
Better suggestions when returning macro calls.
Suggest changeing all the break expressions in a loop, not just the final statement.
Don't lint divergent functions.
Don't suggest returning the result of any divergent fuction.
2021-04-22 09:13:06 -04:00

125 lines
2 KiB
Rust

// run-rustfix
#![warn(clippy::implicit_return)]
#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
fn test_end_of_fn() -> bool {
if true {
// no error!
return true;
}
return true
}
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 },
}
}
fn test_match_with_unreachable(x: bool) -> bool {
match x {
true => return false,
false => unreachable!(),
}
}
fn test_loop() -> bool {
loop {
return true;
}
}
fn test_loop_with_block() -> bool {
loop {
{
return true;
}
}
}
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 macro_branch_test() -> bool {
macro_rules! m {
($t:expr, $f:expr) => {
if true { $t } else { $f }
};
}
return m!(true, false)
}
fn loop_test() -> bool {
'outer: loop {
if true {
return true;
}
let _ = loop {
if false {
return false;
}
if true {
break true;
}
};
}
}
fn loop_macro_test() -> bool {
macro_rules! m {
($e:expr) => {
break $e
};
}
return loop {
m!(true);
}
}
fn divergent_test() -> bool {
fn diverge() -> ! {
panic!()
}
diverge()
}
fn main() {}