]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2497-if-let-chains/then-else-blocks.rs
Rollup merge of #105758 - Nilstrieb:typeck-results-mod, r=compiler-errors
[rust.git] / src / test / ui / rfc-2497-if-let-chains / then-else-blocks.rs
1 // run-pass
2
3 #![feature(if_let_guard, let_chains)]
4
5 fn check_if_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
6     if let Some(first) = opt
7         && let Some(second) = first
8         && let Some(third) = second
9         && third == value
10     {
11         true
12     }
13     else {
14         false
15     }
16 }
17
18 fn check_let_guard(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
19     match opt {
20         Some(first) if let Some(second) = first && let Some(third) = second && third == value => {
21             true
22         }
23         _ => {
24             false
25         }
26     }
27 }
28
29 fn check_while_let(opt: Option<Option<Option<i32>>>, value: i32) -> bool {
30     while let Some(first) = opt
31         && let Some(second) = first
32         && let Some(third) = second
33         && third == value
34     {
35         return true;
36     }
37     false
38 }
39
40 fn main() {
41     assert_eq!(check_if_let(Some(Some(Some(1))), 1), true);
42     assert_eq!(check_if_let(Some(Some(Some(1))), 9), false);
43
44     assert_eq!(check_let_guard(Some(Some(Some(1))), 1), true);
45     assert_eq!(check_let_guard(Some(Some(Some(1))), 9), false);
46
47     assert_eq!(check_while_let(Some(Some(Some(1))), 1), true);
48     assert_eq!(check_while_let(Some(Some(Some(1))), 9), false);
49 }