2024-06-19 13:16:09 -05:00
|
|
|
//@aux-build: proc_macros.rs
|
|
|
|
|
2019-09-20 02:07:13 -05:00
|
|
|
#![warn(clippy::implicit_return)]
|
2021-05-06 04:51:22 -05:00
|
|
|
#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
|
2019-09-20 02:07:13 -05:00
|
|
|
|
2024-06-19 13:16:09 -05:00
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::with_span;
|
|
|
|
|
2019-09-20 02:07:13 -05:00
|
|
|
fn test_end_of_fn() -> bool {
|
|
|
|
if true {
|
|
|
|
// no error!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_if_block() -> bool {
|
2021-03-12 08:30:50 -06:00
|
|
|
if true { return true } else { return false }
|
2019-09-20 02:07:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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")
|
|
|
|
}
|
|
|
|
|
2021-05-06 04:51:22 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-09-20 02:07:13 -05:00
|
|
|
}
|
2021-05-06 04:51:22 -05:00
|
|
|
|
|
|
|
fn loop_macro_test() -> bool {
|
|
|
|
macro_rules! m {
|
|
|
|
($e:expr) => {
|
|
|
|
break $e
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return loop {
|
|
|
|
m!(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn divergent_test() -> bool {
|
|
|
|
fn diverge() -> ! {
|
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
diverge()
|
|
|
|
}
|
|
|
|
|
|
|
|
// issue #6940
|
|
|
|
async fn foo() -> bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|
2022-06-30 03:50:09 -05:00
|
|
|
|
|
|
|
fn check_expect() -> bool {
|
|
|
|
if true {
|
|
|
|
// no error!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[expect(clippy::implicit_return)]
|
|
|
|
true
|
|
|
|
}
|
2024-06-19 13:16:09 -05:00
|
|
|
|
|
|
|
with_span!(
|
|
|
|
span
|
|
|
|
|
|
|
|
fn dont_lint_proc_macro(x: usize) -> usize{
|
|
|
|
x
|
|
|
|
}
|
|
|
|
);
|