]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #![warn(clippy::blocks_in_if_conditions)] |
2 | #![allow(unused, clippy::let_and_return)] | |
3 | ||
4 | fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val: T) -> bool { | |
5 | pfn(val) | |
6 | } | |
7 | ||
8 | fn pred_test() { | |
9 | let v = 3; | |
10 | let sky = "blue"; | |
11 | // This is a sneaky case, where the block isn't directly in the condition, | |
12 | // but is actually inside a closure that the condition is using. | |
13 | // The same principle applies -- add some extra expressions to make sure | |
14 | // linter isn't confused by them. | |
15 | if v == 3 | |
16 | && sky == "blue" | |
17 | && predicate( | |
18 | |x| { | |
19 | let target = 3; | |
20 | x == target | |
21 | }, | |
22 | v, | |
23 | ) | |
24 | {} | |
25 | ||
26 | if predicate( | |
27 | |x| { | |
28 | let target = 3; | |
29 | x == target | |
30 | }, | |
31 | v, | |
32 | ) {} | |
33 | } | |
34 | ||
35 | fn closure_without_block() { | |
36 | if predicate(|x| x == 3, 6) {} | |
37 | } | |
38 | ||
39 | fn macro_in_closure() { | |
40 | let option = Some(true); | |
41 | ||
42 | if option.unwrap_or_else(|| unimplemented!()) { | |
43 | unimplemented!() | |
44 | } | |
45 | } | |
46 | ||
47 | #[rustfmt::skip] | |
48 | fn main() { | |
49 | let mut range = 0..10; | |
50 | range.all(|i| {i < 10} ); | |
51 | ||
52 | let v = vec![1, 2, 3]; | |
53 | if v.into_iter().any(|x| {x == 4}) { | |
54 | println!("contains 4!"); | |
55 | } | |
56 | } |