]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/hygienic-labels-in-let.rs
auto merge of #15210 : luqmana/rust/windoc, 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 #![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! run_once {
23     ($e: expr) => {
24         // ditto
25         'x: for _ in range(0i, 1) { $e }
26     }
27 }
28
29 pub fn main() {
30     let mut i = 0i;
31
32     let j: int = {
33         'x: loop {
34             // this 'x should refer to the outer loop, lexically
35             loop_x!(break 'x);
36             i += 1;
37         }
38         i + 1
39     };
40     assert_eq!(j, 1i);
41
42     let k: int = {
43         'x: for _ in range(0i, 1) {
44             // ditto
45             loop_x!(break 'x);
46             i += 1;
47         }
48         i + 1
49     };
50     assert_eq!(k, 1i);
51
52     let n: int = {
53         'x: for _ in range(0i, 1) {
54             // ditto
55             run_once!(continue 'x);
56             i += 1;
57         }
58         i + 1
59     };
60     assert_eq!(n, 1i);
61 }