]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs
Auto merge of #97191 - wesleywiser:main_thread_name, r=ChrisDenton
[rust.git] / src / tools / clippy / tests / ui / blocks_in_if_conditions_closure.rs
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 fn closure(_: impl FnMut()) -> bool {
48     true
49 }
50
51 fn function_with_empty_closure() {
52     if closure(|| {}) {}
53 }
54
55 #[rustfmt::skip]
56 fn main() {
57     let mut range = 0..10;
58     range.all(|i| {i < 10} );
59
60     let v = vec![1, 2, 3];
61     if v.into_iter().any(|x| {x == 4}) {
62         println!("contains 4!");
63     }
64 }