]> git.lizzy.rs Git - rust.git/blob - tests/ui/implicit_return.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / implicit_return.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::implicit_return)]
11
12 fn test_end_of_fn() -> bool {
13     if true {
14         // no error!
15         return true;
16     }
17     true
18 }
19
20 #[allow(clippy::needless_bool)]
21 fn test_if_block() -> bool {
22     if true {
23         true
24     } else {
25         false
26     }
27 }
28
29 #[allow(clippy::match_bool)]
30 #[rustfmt::skip]
31 fn test_match(x: bool) -> bool {
32     match x {
33         true => false,
34         false => { true },
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 fn test_closure() {
66     #[rustfmt::skip]
67     let _ = || { true };
68     let _ = || true;
69 }
70
71 fn main() {
72     let _ = test_end_of_fn();
73     let _ = test_if_block();
74     let _ = test_match(true);
75     let _ = test_loop();
76     let _ = test_loop_with_block();
77     let _ = test_loop_with_nests();
78     test_closure();
79 }