]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/implicit_return.fixed
New upstream version 1.54.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / implicit_return.fixed
CommitLineData
17df50a5 1// edition:2018
f20569fa
XL
2// run-rustfix
3
4#![warn(clippy::implicit_return)]
17df50a5 5#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
f20569fa
XL
6
7fn test_end_of_fn() -> bool {
8 if true {
9 // no error!
10 return true;
11 }
12
13 return true
14}
15
f20569fa
XL
16fn test_if_block() -> bool {
17 if true { return true } else { return false }
18}
19
20#[rustfmt::skip]
21fn test_match(x: bool) -> bool {
22 match x {
23 true => return false,
24 false => { return true },
25 }
26}
27
f20569fa
XL
28fn test_match_with_unreachable(x: bool) -> bool {
29 match x {
30 true => return false,
31 false => unreachable!(),
32 }
33}
34
f20569fa
XL
35fn test_loop() -> bool {
36 loop {
37 return true;
38 }
39}
40
f20569fa
XL
41fn test_loop_with_block() -> bool {
42 loop {
43 {
44 return true;
45 }
46 }
47}
48
f20569fa
XL
49fn test_loop_with_nests() -> bool {
50 loop {
51 if true {
52 return true;
53 } else {
54 let _ = true;
55 }
56 }
57}
58
59#[allow(clippy::redundant_pattern_matching)]
60fn test_loop_with_if_let() -> bool {
61 loop {
62 if let Some(x) = Some(true) {
63 return x;
64 }
65 }
66}
67
68fn test_closure() {
69 #[rustfmt::skip]
70 let _ = || { return true };
71 let _ = || return true;
72}
73
74fn test_panic() -> bool {
75 panic!()
76}
77
78fn test_return_macro() -> String {
79 return format!("test {}", "test")
80}
81
17df50a5
XL
82fn macro_branch_test() -> bool {
83 macro_rules! m {
84 ($t:expr, $f:expr) => {
85 if true { $t } else { $f }
86 };
87 }
88 return m!(true, false)
89}
90
91fn loop_test() -> bool {
92 'outer: loop {
93 if true {
94 return true;
95 }
96
97 let _ = loop {
98 if false {
99 return false;
100 }
101 if true {
102 break true;
103 }
104 };
105 }
f20569fa 106}
17df50a5
XL
107
108fn loop_macro_test() -> bool {
109 macro_rules! m {
110 ($e:expr) => {
111 break $e
112 };
113 }
114 return loop {
115 m!(true);
116 }
117}
118
119fn divergent_test() -> bool {
120 fn diverge() -> ! {
121 panic!()
122 }
123 diverge()
124}
125
126// issue #6940
127async fn foo() -> bool {
128 return true
129}
130
131fn main() {}