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