2014-05-05 06:16:16 +08:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|