]> git.lizzy.rs Git - rust.git/blob - tests/ui/implicit_return.rs
false positives fixes of `implicit_return`
[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
9     true
10 }
11
12 #[allow(clippy::needless_bool)]
13 fn test_if_block() -> bool {
14     if true {
15         true
16     } else {
17         false
18     }
19 }
20
21 #[allow(clippy::match_bool)]
22 #[rustfmt::skip]
23 fn test_match(x: bool) -> bool {
24     match x {
25         true => false,
26         false => { true },
27     }
28 }
29
30 #[allow(clippy::match_bool, clippy::needless_return)]
31 fn test_match_with_unreachable(x: bool) -> bool {
32     match x {
33         true => return false,
34         false => unreachable!(),
35     }
36 }
37
38 #[allow(clippy::never_loop)]
39 fn test_loop() -> bool {
40     loop {
41         break true;
42     }
43 }
44
45 #[allow(clippy::never_loop)]
46 fn test_loop_with_block() -> bool {
47     loop {
48         {
49             break true;
50         }
51     }
52 }
53
54 #[allow(clippy::never_loop)]
55 fn test_loop_with_nests() -> bool {
56     loop {
57         if true {
58             break true;
59         } else {
60             let _ = true;
61         }
62     }
63 }
64
65 #[allow(clippy::redundant_pattern_matching)]
66 fn test_loop_with_if_let() -> bool {
67     loop {
68         if let Some(x) = Some(true) {
69             return x;
70         }
71     }
72 }
73
74 fn test_closure() {
75     #[rustfmt::skip]
76     let _ = || { true };
77     let _ = || true;
78 }
79
80 fn test_return_never() -> ! {
81     panic!()
82 }
83
84 fn test_panic() -> bool {
85     panic!()
86 }
87
88 fn test_return_macro() -> String {
89     format!("test {}", "test")
90 }
91
92 fn main() {
93     let _ = test_end_of_fn();
94     let _ = test_if_block();
95     let _ = test_match(true);
96     let _ = test_match_with_unreachable(true);
97     let _ = test_loop();
98     let _ = test_loop_with_block();
99     let _ = test_loop_with_nests();
100     let _ = test_loop_with_if_let();
101     test_closure();
102     let _ = test_return_macro();
103 }