]> git.proxmox.com Git - rustc.git/blob - src/test/ui/hygiene/hygienic-labels.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / ui / hygiene / hygienic-labels.rs
1 // run-pass
2 #![allow(unreachable_code)]
3 // Test that labels injected by macros do not break hygiene.
4
5 // Issue #24278: The label/lifetime shadowing checker from #24162
6 // conservatively ignores hygiene, and thus issues warnings that are
7 // both true- and false-positives for this test.
8
9 macro_rules! loop_x {
10 ($e: expr) => {
11 // $e shouldn't be able to interact with this 'x
12 'x: loop { $e }
13 }
14 }
15
16 macro_rules! run_once {
17 ($e: expr) => {
18 // ditto
19 'x: for _ in 0..1 { $e }
20 }
21 }
22
23 macro_rules! while_x {
24 ($e: expr) => {
25 // ditto
26 'x: while 1 + 1 == 2 { $e }
27 }
28 }
29
30 pub fn main() {
31 'x: for _ in 0..1 {
32 // this 'x should refer to the outer loop, lexically
33 loop_x!(break 'x);
34 panic!("break doesn't act hygienically inside for loop");
35 }
36
37 'x: loop {
38 // ditto
39 loop_x!(break 'x);
40 panic!("break doesn't act hygienically inside infinite loop");
41 }
42
43 'x: while 1 + 1 == 2 {
44 while_x!(break 'x);
45 panic!("break doesn't act hygienically inside infinite while loop");
46 }
47
48 'x: for _ in 0..1 {
49 // ditto
50 run_once!(continue 'x);
51 panic!("continue doesn't act hygienically inside for loop");
52 }
53 }