]> git.lizzy.rs Git - rust.git/blob - tests/ui/block_in_if_condition_closure.rs
Auto merge of #5522 - CrazyRoka:match_vec_item, r=phansch
[rust.git] / tests / ui / block_in_if_condition_closure.rs
1 #![warn(clippy::block_in_if_condition_expr)]
2 #![warn(clippy::block_in_if_condition_stmt)]
3 #![allow(unused, clippy::let_and_return)]
4
5 fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val: T) -> bool {
6     pfn(val)
7 }
8
9 fn pred_test() {
10     let v = 3;
11     let sky = "blue";
12     // This is a sneaky case, where the block isn't directly in the condition,
13     // but is actually nside a closure that the condition is using.
14     // The same principle applies -- add some extra expressions to make sure
15     // linter isn't confused by them.
16     if v == 3
17         && sky == "blue"
18         && predicate(
19             |x| {
20                 let target = 3;
21                 x == target
22             },
23             v,
24         )
25     {}
26
27     if predicate(
28         |x| {
29             let target = 3;
30             x == target
31         },
32         v,
33     ) {}
34 }
35
36 fn closure_without_block() {
37     if predicate(|x| x == 3, 6) {}
38 }
39
40 fn macro_in_closure() {
41     let option = Some(true);
42
43     if option.unwrap_or_else(|| unimplemented!()) {
44         unimplemented!()
45     }
46 }
47
48 fn main() {}