]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issue-13027.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 // Tests that match expression handles overlapped literal and range
13 // properly in the presence of guard function.
15 #![feature(slice_patterns)]
17 fn val() -> usize { 1 }
19 static CONST
: usize = 1;
25 multi_pats_shadow_lit();
26 multi_pats_shadow_range();
27 lit_shadow_multi_pats();
28 range_shadow_multi_pats();
32 fn lit_shadow_range() {
33 assert_eq
!(2, match 1 {
40 assert_eq
!(2, match x
+1 {
47 assert_eq
!(2, match val() {
53 assert_eq
!(2, match CONST
{
60 // value is out of the range of second arm, should match wildcard pattern
61 assert_eq
!(3, match 3 {
68 fn range_shadow_lit() {
69 assert_eq
!(2, match 1 {
76 assert_eq
!(2, match x
+1 {
83 assert_eq
!(2, match val() {
89 assert_eq
!(2, match CONST
{
97 assert_eq
!(3, match 3 {
104 fn range_shadow_range() {
105 assert_eq
!(2, match 1 {
112 assert_eq
!(2, match x
+1 {
119 assert_eq
!(2, match val() {
125 assert_eq
!(2, match CONST
{
133 assert_eq
!(3, match 5 {
140 fn multi_pats_shadow_lit() {
141 assert_eq
!(2, match 1 {
143 0 | 1...10 if false => 1,
149 fn multi_pats_shadow_range() {
150 assert_eq
!(2, match 1 {
152 0 | 1...10 if false => 1,
158 fn lit_shadow_multi_pats() {
159 assert_eq
!(2, match 1 {
167 fn range_shadow_multi_pats() {
168 assert_eq
!(2, match 1 {
180 // This test basically mimics how trace_macros! macro is implemented,
181 // which is a rare combination of vector patterns, multiple wild-card
182 // patterns and guard functions.
183 let r
= match [Foo
::Bar(0, false)] {
184 [Foo
::Bar(_
, pred
)] if pred
=> 1,
185 [Foo
::Bar(_
, pred
)] if !pred
=> 2,