]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/needless_return.rs
Merge commit '3d0b0e66afdfaa519d8855b338b35b4605775945' into clippyup
[rust.git] / src / tools / clippy / tests / ui / needless_return.rs
1 // run-rustfix
2
3 #![allow(unused, clippy::needless_bool)]
4 #![allow(clippy::if_same_then_else, clippy::single_match)]
5 #![warn(clippy::needless_return)]
6
7 macro_rules! the_answer {
8     () => {
9         42
10     };
11 }
12
13 fn test_end_of_fn() -> bool {
14     if true {
15         // no error!
16         return true;
17     }
18     return true;
19 }
20
21 fn test_no_semicolon() -> bool {
22     return true;
23 }
24
25 fn test_if_block() -> bool {
26     if true {
27         return true;
28     } else {
29         return false;
30     }
31 }
32
33 fn test_match(x: bool) -> bool {
34     match x {
35         true => return false,
36         false => {
37             return true;
38         },
39     }
40 }
41
42 fn test_closure() {
43     let _ = || {
44         return true;
45     };
46     let _ = || return true;
47 }
48
49 fn test_macro_call() -> i32 {
50     return the_answer!();
51 }
52
53 fn test_void_fun() {
54     return;
55 }
56
57 fn test_void_if_fun(b: bool) {
58     if b {
59         return;
60     } else {
61         return;
62     }
63 }
64
65 fn test_void_match(x: u32) {
66     match x {
67         0 => (),
68         _ => return,
69     }
70 }
71
72 fn read_line() -> String {
73     use std::io::BufRead;
74     let stdin = ::std::io::stdin();
75     return stdin.lock().lines().next().unwrap().unwrap();
76 }
77
78 fn borrows_but_not_last(value: bool) -> String {
79     if value {
80         use std::io::BufRead;
81         let stdin = ::std::io::stdin();
82         let _a = stdin.lock().lines().next().unwrap().unwrap();
83         return String::from("test");
84     } else {
85         return String::new();
86     }
87 }
88
89 fn main() {
90     let _ = test_end_of_fn();
91     let _ = test_no_semicolon();
92     let _ = test_if_block();
93     let _ = test_match(true);
94     test_closure();
95 }