2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-08-31 08:02:01 -05:00
|
|
|
#![allow(non_shorthand_field_patterns)]
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2012-10-24 20:47:59 -05:00
|
|
|
enum Foo {
|
|
|
|
Bar {
|
2015-03-25 19:06:52 -05:00
|
|
|
x: isize,
|
|
|
|
y: isize
|
2012-10-24 20:47:59 -05:00
|
|
|
},
|
|
|
|
Baz {
|
2013-09-26 01:26:09 -05:00
|
|
|
x: f64,
|
|
|
|
y: f64
|
2012-10-24 20:47:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn f(x: &Foo) {
|
|
|
|
match *x {
|
2014-11-06 02:05:53 -06:00
|
|
|
Foo::Baz { x: x, y: y } => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 1.0);
|
|
|
|
assert_eq!(y, 2.0);
|
2012-10-24 20:47:59 -05:00
|
|
|
}
|
2014-11-06 02:05:53 -06:00
|
|
|
Foo::Bar { y: y, x: x } => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 1);
|
|
|
|
assert_eq!(y, 2);
|
2012-10-24 20:47:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2014-11-06 02:05:53 -06:00
|
|
|
let x = Foo::Bar { x: 1, y: 2 };
|
2012-10-24 20:47:59 -05:00
|
|
|
f(&x);
|
2014-11-06 02:05:53 -06:00
|
|
|
let y = Foo::Baz { x: 1.0, y: 2.0 };
|
2012-10-24 20:47:59 -05:00
|
|
|
f(&y);
|
|
|
|
}
|