]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_return.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[rust.git] / tests / ui / needless_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::needless_return)]
11
12 fn test_end_of_fn() -> bool {
13     if true {
14         // no error!
15         return true;
16     }
17     return true;
18 }
19
20 fn test_no_semicolon() -> bool {
21     return true;
22 }
23
24 fn test_if_block() -> bool {
25     if true {
26         return true;
27     } else {
28         return false;
29     }
30 }
31
32 fn test_match(x: bool) -> bool {
33     match x {
34         true => return false,
35         false => {
36             return true;
37         },
38     }
39 }
40
41 fn test_closure() {
42     let _ = || {
43         return true;
44     };
45     let _ = || return true;
46 }
47
48 fn main() {
49     let _ = test_end_of_fn();
50     let _ = test_no_semicolon();
51     let _ = test_if_block();
52     let _ = test_match(true);
53     test_closure();
54 }