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