]> git.proxmox.com Git - rustc.git/blob - 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
1 // edition:2018
2 // run-rustfix
3
4 #![warn(clippy::implicit_return)]
5 #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
6
7 fn test_end_of_fn() -> bool {
8 if true {
9 // no error!
10 return true;
11 }
12
13 return true
14 }
15
16 fn test_if_block() -> bool {
17 if true { return true } else { return false }
18 }
19
20 #[rustfmt::skip]
21 fn test_match(x: bool) -> bool {
22 match x {
23 true => return false,
24 false => { return true },
25 }
26 }
27
28 fn test_match_with_unreachable(x: bool) -> bool {
29 match x {
30 true => return false,
31 false => unreachable!(),
32 }
33 }
34
35 fn test_loop() -> bool {
36 loop {
37 return true;
38 }
39 }
40
41 fn test_loop_with_block() -> bool {
42 loop {
43 {
44 return true;
45 }
46 }
47 }
48
49 fn 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)]
60 fn test_loop_with_if_let() -> bool {
61 loop {
62 if let Some(x) = Some(true) {
63 return x;
64 }
65 }
66 }
67
68 fn test_closure() {
69 #[rustfmt::skip]
70 let _ = || { return true };
71 let _ = || return true;
72 }
73
74 fn test_panic() -> bool {
75 panic!()
76 }
77
78 fn test_return_macro() -> String {
79 return format!("test {}", "test")
80 }
81
82 fn 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
91 fn 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 }
106 }
107
108 fn 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
119 fn divergent_test() -> bool {
120 fn diverge() -> ! {
121 panic!()
122 }
123 diverge()
124 }
125
126 // issue #6940
127 async fn foo() -> bool {
128 return true
129 }
130
131 fn main() {}