2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2022-06-25 07:16:31 -05:00
|
|
|
#![feature(lint_reasons)]
|
2018-12-05 07:39:09 -06:00
|
|
|
#![warn(clippy::implicit_return)]
|
2021-04-01 21:46:10 -05:00
|
|
|
#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
|
2018-12-04 18:59:09 -06:00
|
|
|
|
|
|
|
fn test_end_of_fn() -> bool {
|
|
|
|
if true {
|
|
|
|
// no error!
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-15 09:02:50 -05:00
|
|
|
|
2018-12-04 18:59:09 -06:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_if_block() -> bool {
|
2021-03-01 11:53:33 -06:00
|
|
|
if true { true } else { false }
|
2018-12-04 18:59:09 -06:00
|
|
|
}
|
|
|
|
|
2018-12-10 17:59:59 -06:00
|
|
|
#[rustfmt::skip]
|
2018-12-04 18:59:09 -06:00
|
|
|
fn test_match(x: bool) -> bool {
|
|
|
|
match x {
|
|
|
|
true => false,
|
2018-12-10 17:59:59 -06:00
|
|
|
false => { true },
|
2018-12-04 18:59:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 06:45:22 -06:00
|
|
|
fn test_match_with_unreachable(x: bool) -> bool {
|
|
|
|
match x {
|
|
|
|
true => return false,
|
|
|
|
false => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 07:39:09 -06:00
|
|
|
fn test_loop() -> bool {
|
|
|
|
loop {
|
|
|
|
break true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 08:42:02 -06:00
|
|
|
fn test_loop_with_block() -> bool {
|
|
|
|
loop {
|
|
|
|
{
|
|
|
|
break true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_loop_with_nests() -> bool {
|
|
|
|
loop {
|
|
|
|
if true {
|
2018-12-16 15:20:05 -06:00
|
|
|
break true;
|
2018-12-27 09:17:45 -06:00
|
|
|
} else {
|
2018-12-16 15:20:05 -06:00
|
|
|
let _ = true;
|
2018-12-16 08:42:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 06:45:22 -06:00
|
|
|
#[allow(clippy::redundant_pattern_matching)]
|
|
|
|
fn test_loop_with_if_let() -> bool {
|
|
|
|
loop {
|
|
|
|
if let Some(x) = Some(true) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 18:59:09 -06:00
|
|
|
fn test_closure() {
|
2018-12-10 17:59:59 -06:00
|
|
|
#[rustfmt::skip]
|
|
|
|
let _ = || { true };
|
2018-12-04 18:59:09 -06:00
|
|
|
let _ = || true;
|
|
|
|
}
|
|
|
|
|
2019-07-15 09:02:50 -05:00
|
|
|
fn test_panic() -> bool {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_return_macro() -> String {
|
|
|
|
format!("test {}", "test")
|
|
|
|
}
|
|
|
|
|
2021-04-01 21:46:10 -05:00
|
|
|
fn macro_branch_test() -> bool {
|
|
|
|
macro_rules! m {
|
|
|
|
($t:expr, $f:expr) => {
|
|
|
|
if true { $t } else { $f }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
m!(true, false)
|
2018-12-04 18:59:09 -06:00
|
|
|
}
|
2021-04-01 21:46:10 -05:00
|
|
|
|
|
|
|
fn loop_test() -> bool {
|
|
|
|
'outer: loop {
|
|
|
|
if true {
|
|
|
|
break true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let _ = loop {
|
|
|
|
if false {
|
|
|
|
break 'outer false;
|
|
|
|
}
|
|
|
|
if true {
|
|
|
|
break true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn loop_macro_test() -> bool {
|
|
|
|
macro_rules! m {
|
|
|
|
($e:expr) => {
|
|
|
|
break $e
|
|
|
|
};
|
|
|
|
}
|
|
|
|
loop {
|
|
|
|
m!(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn divergent_test() -> bool {
|
|
|
|
fn diverge() -> ! {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
diverge()
|
|
|
|
}
|
|
|
|
|
2021-04-02 16:53:14 -05:00
|
|
|
// issue #6940
|
|
|
|
async fn foo() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2021-04-01 21:46:10 -05:00
|
|
|
fn main() {}
|
2022-06-25 07:16:31 -05:00
|
|
|
|
|
|
|
fn check_expect() -> bool {
|
|
|
|
if true {
|
|
|
|
// no error!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[expect(clippy::implicit_return)]
|
|
|
|
true
|
|
|
|
}
|