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