2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2013-05-23 02:51:21 +00:00
|
|
|
enum Enum {
|
2015-03-26 00:06:52 +00:00
|
|
|
Foo { foo: usize },
|
|
|
|
Bar { bar: usize }
|
2013-05-23 02:51:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn fun1(e1: &Enum, e2: &Enum) -> usize {
|
2013-05-23 02:51:21 +00:00
|
|
|
match (e1, e2) {
|
2014-11-06 08:05:53 +00:00
|
|
|
(&Enum::Foo { foo: _ }, &Enum::Foo { foo: _ }) => 0,
|
|
|
|
(&Enum::Foo { foo: _ }, &Enum::Bar { bar: _ }) => 1,
|
|
|
|
(&Enum::Bar { bar: _ }, &Enum::Bar { bar: _ }) => 2,
|
|
|
|
(&Enum::Bar { bar: _ }, &Enum::Foo { foo: _ }) => 3,
|
2013-05-23 02:51:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn fun2(e1: &Enum, e2: &Enum) -> usize {
|
2013-05-23 02:51:21 +00:00
|
|
|
match (e1, e2) {
|
2014-11-06 08:05:53 +00:00
|
|
|
(&Enum::Foo { foo: _ }, &Enum::Foo { foo: _ }) => 0,
|
|
|
|
(&Enum::Foo { foo: _ }, _ ) => 1,
|
|
|
|
(&Enum::Bar { bar: _ }, &Enum::Bar { bar: _ }) => 2,
|
|
|
|
(&Enum::Bar { bar: _ }, _ ) => 3,
|
2013-05-23 02:51:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2014-11-06 08:05:53 +00:00
|
|
|
let foo = Enum::Foo { foo: 1 };
|
|
|
|
let bar = Enum::Bar { bar: 1 };
|
2013-05-23 02:51:21 +00:00
|
|
|
|
|
|
|
assert_eq!(fun1(&foo, &foo), 0);
|
|
|
|
assert_eq!(fun1(&foo, &bar), 1);
|
|
|
|
assert_eq!(fun1(&bar, &bar), 2);
|
|
|
|
assert_eq!(fun1(&bar, &foo), 3);
|
|
|
|
|
|
|
|
assert_eq!(fun2(&foo, &foo), 0);
|
|
|
|
assert_eq!(fun2(&foo, &bar), 1); // fun2 returns 0
|
|
|
|
assert_eq!(fun2(&bar, &bar), 2);
|
|
|
|
assert_eq!(fun2(&bar, &foo), 3); // fun2 returns 2
|
|
|
|
}
|