2019-07-27 17:56:36 -05:00
|
|
|
// run-pass
|
2018-09-07 10:52:49 -05:00
|
|
|
|
|
|
|
struct A { a: Box<i32> }
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
fn get(&self) -> i32 { *self.a }
|
|
|
|
}
|
|
|
|
|
2019-07-27 17:56:36 -05:00
|
|
|
fn foo(n: i32) -> i32 {
|
2018-09-07 10:52:49 -05:00
|
|
|
let x = A { a: Box::new(n) };
|
|
|
|
let y = match x {
|
|
|
|
A { a: v } if *v == 42 => v,
|
|
|
|
_ => Box::new(0),
|
|
|
|
};
|
2019-07-27 17:56:36 -05:00
|
|
|
*y
|
2018-09-07 10:52:49 -05:00
|
|
|
}
|
|
|
|
|
2019-07-27 17:56:36 -05:00
|
|
|
fn bar(n: i32) -> i32 {
|
2018-09-07 10:52:49 -05:00
|
|
|
let x = A { a: Box::new(n) };
|
|
|
|
let y = match x {
|
|
|
|
A { a: v } if x.get() == 42 => v,
|
|
|
|
_ => Box::new(0),
|
|
|
|
};
|
2019-07-27 17:56:36 -05:00
|
|
|
*y
|
2018-09-07 10:52:49 -05:00
|
|
|
}
|
|
|
|
|
2019-07-27 17:56:36 -05:00
|
|
|
fn baz(n: i32) -> i32 {
|
2018-09-07 10:52:49 -05:00
|
|
|
let x = A { a: Box::new(n) };
|
|
|
|
let y = match x {
|
|
|
|
A { a: v } if *v.clone() == 42 => v,
|
|
|
|
_ => Box::new(0),
|
|
|
|
};
|
2019-07-27 17:56:36 -05:00
|
|
|
*y
|
2018-09-07 10:52:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-07-27 17:56:36 -05:00
|
|
|
assert_eq!(foo(107), 0);
|
|
|
|
assert_eq!(foo(42), 42);
|
|
|
|
assert_eq!(bar(107), 0);
|
|
|
|
assert_eq!(bar(42), 42);
|
|
|
|
assert_eq!(baz(107), 0);
|
|
|
|
assert_eq!(baz(42), 42);
|
2018-09-07 10:52:49 -05:00
|
|
|
}
|