]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/hygienic-labels-in-let.rs
auto merge of #16940 : treeman/rust/fail-non-utf8, r=pnkfelix
[rust.git] / src / test / run-pass / hygienic-labels-in-let.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.
4 //
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.
10
11 // ignore-pretty: pprust doesn't print hygiene output
12
13 #![feature(macro_rules)]
14
15 macro_rules! loop_x {
16     ($e: expr) => {
17         // $e shouldn't be able to interact with this 'x
18         'x: loop { $e }
19     }
20 }
21
22 macro_rules! while_true {
23     ($e: expr) => {
24         // $e shouldn't be able to interact with this 'x
25         'x: while 1i + 1 == 2 { $e }
26     }
27 }
28
29 macro_rules! run_once {
30     ($e: expr) => {
31         // ditto
32         'x: for _ in range(0i, 1) { $e }
33     }
34 }
35
36 pub fn main() {
37     let mut i = 0i;
38
39     let j: int = {
40         'x: loop {
41             // this 'x should refer to the outer loop, lexically
42             loop_x!(break 'x);
43             i += 1;
44         }
45         i + 1
46     };
47     assert_eq!(j, 1i);
48
49     let k: int = {
50         'x: for _ in range(0i, 1) {
51             // ditto
52             loop_x!(break 'x);
53             i += 1;
54         }
55         i + 1
56     };
57     assert_eq!(k, 1i);
58
59     let l: int = {
60         'x: for _ in range(0i, 1) {
61             // ditto
62             while_true!(break 'x);
63             i += 1;
64         }
65         i + 1
66     };
67     assert_eq!(l, 1i);
68
69     let n: int = {
70         'x: for _ in range(0i, 1) {
71             // ditto
72             run_once!(continue 'x);
73             i += 1;
74         }
75         i + 1
76     };
77     assert_eq!(n, 1i);
78 }