]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_return.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / needless_return.rs
1 #![warn(clippy::needless_return)]
2
3 macro_rules! the_answer {
4     () => {
5         42
6     };
7 }
8
9 fn test_end_of_fn() -> bool {
10     if true {
11         // no error!
12         return true;
13     }
14     return true;
15 }
16
17 fn test_no_semicolon() -> bool {
18     return true;
19 }
20
21 fn test_if_block() -> bool {
22     if true {
23         return true;
24     } else {
25         return false;
26     }
27 }
28
29 fn test_match(x: bool) -> bool {
30     match x {
31         true => return false,
32         false => {
33             return true;
34         },
35     }
36 }
37
38 fn test_closure() {
39     let _ = || {
40         return true;
41     };
42     let _ = || return true;
43 }
44
45 fn test_macro_call() -> i32 {
46     return the_answer!();
47 }
48
49 fn test_void_fun() {
50     return;
51 }
52
53 fn test_void_if_fun(b: bool) {
54     if b {
55         return;
56     } else {
57         return;
58     }
59 }
60
61 fn test_void_match(x: u32) {
62     match x {
63         0 => (),
64         _ => return,
65     }
66 }
67
68 fn main() {
69     let _ = test_end_of_fn();
70     let _ = test_no_semicolon();
71     let _ = test_if_block();
72     let _ = test_match(true);
73     test_closure();
74 }