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