2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2014-05-05 06:16:16 +08:00
|
|
|
// Test that codegen works correctly when there are multiple refutable
|
|
|
|
// patterns in match expression.
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2014-05-05 06:16:16 +08:00
|
|
|
enum Foo {
|
2015-03-25 17:06:52 -07:00
|
|
|
FooUint(usize),
|
2014-05-05 06:16:16 +08:00
|
|
|
FooNullary,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-11-06 00:05:53 -08:00
|
|
|
let r = match (Foo::FooNullary, 'a') {
|
2018-05-28 19:42:11 -07:00
|
|
|
(Foo::FooUint(..), 'a'..='z') => 1,
|
2015-01-25 22:05:03 +01:00
|
|
|
(Foo::FooNullary, 'x') => 2,
|
2014-05-05 06:16:16 +08:00
|
|
|
_ => 0
|
|
|
|
};
|
|
|
|
assert_eq!(r, 0);
|
|
|
|
|
2014-11-06 00:05:53 -08:00
|
|
|
let r = match (Foo::FooUint(0), 'a') {
|
2018-05-28 19:42:11 -07:00
|
|
|
(Foo::FooUint(1), 'a'..='z') => 1,
|
2015-01-25 22:05:03 +01:00
|
|
|
(Foo::FooUint(..), 'x') => 2,
|
|
|
|
(Foo::FooNullary, 'a') => 3,
|
2014-05-05 06:16:16 +08:00
|
|
|
_ => 0
|
|
|
|
};
|
|
|
|
assert_eq!(r, 0);
|
|
|
|
|
2014-11-06 00:05:53 -08:00
|
|
|
let r = match ('a', Foo::FooUint(0)) {
|
2018-05-28 19:42:11 -07:00
|
|
|
('a'..='z', Foo::FooUint(1)) => 1,
|
2015-01-25 22:05:03 +01:00
|
|
|
('x', Foo::FooUint(..)) => 2,
|
|
|
|
('a', Foo::FooNullary) => 3,
|
2014-05-05 06:16:16 +08:00
|
|
|
_ => 0
|
|
|
|
};
|
|
|
|
assert_eq!(r, 0);
|
|
|
|
|
|
|
|
let r = match ('a', 'a') {
|
2018-05-28 19:42:11 -07:00
|
|
|
('a'..='z', 'b') => 1,
|
|
|
|
('x', 'a'..='z') => 2,
|
2014-05-05 06:16:16 +08:00
|
|
|
_ => 0
|
|
|
|
};
|
|
|
|
assert_eq!(r, 0);
|
|
|
|
|
|
|
|
let r = match ('a', 'a') {
|
2018-05-28 19:42:11 -07:00
|
|
|
('a'..='z', 'b') => 1,
|
|
|
|
('x', 'a'..='z') => 2,
|
2015-01-25 22:05:03 +01:00
|
|
|
('a', 'a') => 3,
|
2014-05-05 06:16:16 +08:00
|
|
|
_ => 0
|
|
|
|
};
|
|
|
|
assert_eq!(r, 3);
|
|
|
|
}
|