2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2013-05-22 19:51:21 -07:00
|
|
|
enum Enum {
|
2015-03-25 17:06:52 -07:00
|
|
|
Foo { foo: usize },
|
|
|
|
Bar { bar: usize }
|
2013-05-22 19:51:21 -07:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
fn fun1(e1: &Enum, e2: &Enum) -> usize {
|
2013-05-22 19:51:21 -07:00
|
|
|
match (e1, e2) {
|
2014-11-06 00:05:53 -08: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-22 19:51:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
fn fun2(e1: &Enum, e2: &Enum) -> usize {
|
2013-05-22 19:51:21 -07:00
|
|
|
match (e1, e2) {
|
2014-11-06 00:05:53 -08: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-22 19:51:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2014-11-06 00:05:53 -08:00
|
|
|
let foo = Enum::Foo { foo: 1 };
|
|
|
|
let bar = Enum::Bar { bar: 1 };
|
2013-05-22 19:51:21 -07: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
|
|
|
|
}
|