]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
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 | mod issue6501 { | |
105 | fn foo(bar: Result<(), ()>) { | |
106 | bar.unwrap_or_else(|_| {}) | |
107 | } | |
108 | ||
109 | fn test_closure() { | |
110 | let _ = || { | |
111 | ||
112 | }; | |
113 | let _ = || {}; | |
114 | } | |
115 | ||
116 | struct Foo; | |
117 | #[allow(clippy::unnecessary_lazy_evaluations)] | |
118 | fn bar(res: Result<Foo, u8>) -> Foo { | |
119 | res.unwrap_or_else(|_| Foo) | |
120 | } | |
121 | } | |
122 | ||
123 | fn main() { | |
124 | let _ = test_end_of_fn(); | |
125 | let _ = test_no_semicolon(); | |
126 | let _ = test_if_block(); | |
127 | let _ = test_match(true); | |
128 | test_closure(); | |
129 | } |