]> git.lizzy.rs Git - rust.git/blob - tests/ui/implicit_return.rs
Auto merge of #3679 - daxpedda:use_self, r=phansch
[rust.git] / tests / ui / implicit_return.rs
1 #![warn(clippy::implicit_return)]
2
3 fn test_end_of_fn() -> bool {
4     if true {
5         // no error!
6         return true;
7     }
8     true
9 }
10
11 #[allow(clippy::needless_bool)]
12 fn test_if_block() -> bool {
13     if true {
14         true
15     } else {
16         false
17     }
18 }
19
20 #[allow(clippy::match_bool)]
21 #[rustfmt::skip]
22 fn test_match(x: bool) -> bool {
23     match x {
24         true => false,
25         false => { true },
26     }
27 }
28
29 #[allow(clippy::match_bool, clippy::needless_return)]
30 fn test_match_with_unreachable(x: bool) -> bool {
31     match x {
32         true => return false,
33         false => unreachable!(),
34     }
35 }
36
37 #[allow(clippy::never_loop)]
38 fn test_loop() -> bool {
39     loop {
40         break true;
41     }
42 }
43
44 #[allow(clippy::never_loop)]
45 fn test_loop_with_block() -> bool {
46     loop {
47         {
48             break true;
49         }
50     }
51 }
52
53 #[allow(clippy::never_loop)]
54 fn test_loop_with_nests() -> bool {
55     loop {
56         if true {
57             break true;
58         } else {
59             let _ = true;
60         }
61     }
62 }
63
64 #[allow(clippy::redundant_pattern_matching)]
65 fn test_loop_with_if_let() -> bool {
66     loop {
67         if let Some(x) = Some(true) {
68             return x;
69         }
70     }
71 }
72
73 fn test_closure() {
74     #[rustfmt::skip]
75     let _ = || { true };
76     let _ = || true;
77 }
78
79 fn main() {
80     let _ = test_end_of_fn();
81     let _ = test_if_block();
82     let _ = test_match(true);
83     let _ = test_match_with_unreachable(true);
84     let _ = test_loop();
85     let _ = test_loop_with_block();
86     let _ = test_loop_with_nests();
87     let _ = test_loop_with_if_let();
88     test_closure();
89 }