]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/hygienic-labels.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / hygienic-labels.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 // Test that labels injected by macros do not break hygiene.
12
13 // Issue #24278: The label/lifetime shadowing checker from #24162
14 // conservatively ignores hygiene, and thus issues warnings that are
15 // both true- and false-positives for this test.
16
17 macro_rules! loop_x {
18     ($e: expr) => {
19         // $e shouldn't be able to interact with this 'x
20         'x: loop { $e }
21     }
22 }
23
24 macro_rules! run_once {
25     ($e: expr) => {
26         // ditto
27         'x: for _ in 0..1 { $e }
28     }
29 }
30
31 macro_rules! while_x {
32     ($e: expr) => {
33         // ditto
34         'x: while 1 + 1 == 2 { $e }
35     }
36 }
37
38 pub fn main() {
39     'x: for _ in 0..1 {
40         // this 'x should refer to the outer loop, lexically
41         loop_x!(break 'x);
42         panic!("break doesn't act hygienically inside for loop");
43     }
44
45     'x: loop {
46         // ditto
47         loop_x!(break 'x);
48         panic!("break doesn't act hygienically inside infinite loop");
49     }
50
51     'x: while 1 + 1 == 2 {
52         while_x!(break 'x);
53         panic!("break doesn't act hygienically inside infinite while loop");
54     }
55
56     'x: for _ in 0..1 {
57         // ditto
58         run_once!(continue 'x);
59         panic!("continue doesn't act hygienically inside for loop");
60     }
61 }