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