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