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