]> git.lizzy.rs Git - rust.git/blob - tests/ui/rfc-0107-bind-by-move-pattern-guards/rfc-basic-examples.rs
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
[rust.git] / tests / ui / rfc-0107-bind-by-move-pattern-guards / rfc-basic-examples.rs
1 // run-pass
2
3 struct A { a: Box<i32> }
4
5 impl A {
6     fn get(&self) -> i32 { *self.a }
7 }
8
9 fn foo(n: i32) -> i32 {
10     let x = A { a: Box::new(n) };
11     let y = match x {
12         A { a: v } if *v == 42 => v,
13         _ => Box::new(0),
14     };
15     *y
16 }
17
18 fn bar(n: i32) -> i32 {
19     let x = A { a: Box::new(n) };
20     let y = match x {
21         A { a: v } if x.get() == 42 => v,
22         _ => Box::new(0),
23     };
24     *y
25 }
26
27 fn baz(n: i32) -> i32 {
28     let x = A { a: Box::new(n) };
29     let y = match x {
30         A { a: v } if *v.clone() == 42 => v,
31         _ => Box::new(0),
32     };
33     *y
34 }
35
36 fn main() {
37     assert_eq!(foo(107), 0);
38     assert_eq!(foo(42), 42);
39     assert_eq!(bar(107), 0);
40     assert_eq!(bar(42), 42);
41     assert_eq!(baz(107), 0);
42     assert_eq!(baz(42), 42);
43 }