]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_return.fixed
Auto merge of #6574 - Jarcho:single_match_eq, r=Manishearth
[rust.git] / tests / ui / needless_return.fixed
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     true
19 }
20
21 fn test_no_semicolon() -> bool {
22     true
23 }
24
25 fn test_if_block() -> bool {
26     if true {
27         true
28     } else {
29         false
30     }
31 }
32
33 fn test_match(x: bool) -> bool {
34     match x {
35         true => false,
36         false => {
37             true
38         },
39     }
40 }
41
42 fn test_closure() {
43     let _ = || {
44         true
45     };
46     let _ = || true;
47 }
48
49 fn test_macro_call() -> i32 {
50     return the_answer!();
51 }
52
53 fn test_void_fun() {
54     
55 }
56
57 fn test_void_if_fun(b: bool) {
58     if b {
59         
60     } else {
61         
62     }
63 }
64
65 fn test_void_match(x: u32) {
66     match x {
67         0 => (),
68         _ => {},
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         String::from("test")
84     } else {
85         String::new()
86     }
87 }
88
89 macro_rules! needed_return {
90     ($e:expr) => {
91         if $e > 3 {
92             return;
93         }
94     };
95 }
96
97 fn test_return_in_macro() {
98     // This will return and the macro below won't be executed. Removing the `return` from the macro
99     // will change semantics.
100     needed_return!(10);
101     needed_return!(0);
102 }
103
104 fn main() {
105     let _ = test_end_of_fn();
106     let _ = test_no_semicolon();
107     let _ = test_if_block();
108     let _ = test_match(true);
109     test_closure();
110 }