]> git.lizzy.rs Git - rust.git/blob - tests/ui/implicit_return.rs
Auto merge of #85538 - r00ster91:iterrepeat, r=Mark-Simulacrum
[rust.git] / tests / ui / implicit_return.rs
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     true
14 }
15
16 fn test_if_block() -> bool {
17     if true { true } else { false }
18 }
19
20 #[rustfmt::skip]
21 fn test_match(x: bool) -> bool {
22     match x {
23         true => false,
24         false => { 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         break true;
38     }
39 }
40
41 fn test_loop_with_block() -> bool {
42     loop {
43         {
44             break true;
45         }
46     }
47 }
48
49 fn test_loop_with_nests() -> bool {
50     loop {
51         if true {
52             break 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 _ = || { true };
71     let _ = || true;
72 }
73
74 fn test_panic() -> bool {
75     panic!()
76 }
77
78 fn test_return_macro() -> String {
79     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     m!(true, false)
89 }
90
91 fn loop_test() -> bool {
92     'outer: loop {
93         if true {
94             break true;
95         }
96
97         let _ = loop {
98             if false {
99                 break 'outer 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     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     true
129 }
130
131 fn main() {}