]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/issues/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.
13 // Tests that match expression handles overlapped literal and range
14 // properly in the presence of guard function.
16 fn val() -> usize { 1 }
18 static CONST
: usize = 1;
24 multi_pats_shadow_lit();
25 multi_pats_shadow_range();
26 lit_shadow_multi_pats();
27 range_shadow_multi_pats();
31 fn lit_shadow_range() {
32 assert_eq
!(2, match 1 {
39 assert_eq
!(2, match x
+1 {
46 assert_eq
!(2, match val() {
52 assert_eq
!(2, match CONST
{
59 // value is out of the range of second arm, should match wildcard pattern
60 assert_eq
!(3, match 3 {
67 fn range_shadow_lit() {
68 assert_eq
!(2, match 1 {
75 assert_eq
!(2, match x
+1 {
82 assert_eq
!(2, match val() {
88 assert_eq
!(2, match CONST
{
96 assert_eq
!(3, match 3 {
103 fn range_shadow_range() {
104 assert_eq
!(2, match 1 {
111 assert_eq
!(2, match x
+1 {
118 assert_eq
!(2, match val() {
124 assert_eq
!(2, match CONST
{
132 assert_eq
!(3, match 5 {
139 fn multi_pats_shadow_lit() {
140 assert_eq
!(2, match 1 {
142 0 | 1..=10 if false => 1,
148 fn multi_pats_shadow_range() {
149 assert_eq
!(2, match 1 {
151 0 | 1..=10 if false => 1,
157 fn lit_shadow_multi_pats() {
158 assert_eq
!(2, match 1 {
166 fn range_shadow_multi_pats() {
167 assert_eq
!(2, match 1 {
179 // This test basically mimics how trace_macros! macro is implemented,
180 // which is a rare combination of vector patterns, multiple wild-card
181 // patterns and guard functions.
182 let r
= match [Foo
::Bar(0, false)] {
183 [Foo
::Bar(_
, pred
)] if pred
=> 1,
184 [Foo
::Bar(_
, pred
)] if !pred
=> 2,